Click to See Complete Forum and Search --> : [RESOLVED] Starting Database....


rocky_upadhaya
February 11th, 2010, 05:48 AM
Hello! This is my first project on database....what I want to do is a login page which checks the Username and Password detail from the database and lets in if UserName is true.....

I have created a service-based database named UserInfo.mdf which has a table with 2 columns called UserName and Password......I have also added a values to these columns......Now on the login screen I want to compare the values from the user in Textbox with this value in the database.....and If this matches it must login.......
Please guide me in here what else should I add or do to make it work??


Please Evaluate my attached project.....

boudino
February 12th, 2010, 01:55 AM
You can go way of asp.net and mebership provider, or do it youself with SQL query to DB. In this case, you will need DbConnection (SqlConnection?) and DbCommand executed with ExecuteReader() method of it.

rocky_upadhaya
February 12th, 2010, 02:05 AM
Thanks You for your suggestion....Here is a Updated Program...please have a look through it....
I managed to validate user through the database data but i need help for changing and updating data and database........
I am having a problem in the second window where I want to change password over writing the current password in the data base.....

lost_bg
February 12th, 2010, 07:17 AM
Do you need it to be with a DB? If it is a single user/pass account it can be easilly saved in binary file. I have a similar project - on first run it creates an account (user chosen user and pass) and on each other run, you need to use the user and pass you have chosen to get to form2.

If that would be any help I can provide you with the source code of my project.

rocky_upadhaya
February 12th, 2010, 07:22 AM
Yes I would surely like to see that....Please Upload it here.....On the Other Hand I used database Because I have a plan of extending this application and I surely need the database on that so that I can only add a table to it....any oh! it would be great if I can see your application...Thanks

rocky_upadhaya
February 12th, 2010, 08:26 AM
Someone have suggested me the following code for solving my problem..but it is not updating the data base at all even though it does not give any error at compile or runtime....please have a look at this l...

private void button1_Click(object sender, RoutedEventArgs e)
{
using (var db = new DataClasses1DataContext())
{

var user = db.usrInfo_tables.SingleOrDefault(c => c.Username == txt_usrname.Text.Trim() && c.Password == txt_oldpass.Text.Trim());

if (user == null)
{
MessageBox.Show("Incorrect Username or Old Password!!");
return;
}

user.Password = txt_newpass.Text.Trim();
db.SubmitChanges();
}
}

lost_bg
February 12th, 2010, 10:43 AM
Here is the login modul. I am pretty sure that you can use this file instead of DB, but I am not advance enough to tell you how..

Also check this code, wrote it fast just to show u what i meant:

private void button3_Click(object sender, EventArgs e)
{
string username = textBox1.Text;
string password = textBox2.Text;
string username1, password1;
var db = new databaseDataContext();
var user = db.Users.Single(a => a.ID == 1); // get the user with ID = 1
username1 = user.Username;
password1 = user.Password;
if ((username == username1) && (password == password1))
{
MessageBox.Show("OK");

}

You need to change the ID for the account to 1 for this to work.