Ultimate V

how do i tell a button to cheak whats in the username text box is equal to what is in a users table database

if you know what i mean...




Re: Visual C# Express Edition login form

VS_Programmer

It really depends on your database type.

Try this:

void buttonSubmit_Click(object sender, EventArgs e)

{

if (usernameTextbox.Text == makedatabasecallhere)

{

//logged in successfully

}

else

{

//error in login

}

}

Hope this helps





Re: Visual C# Express Edition login form

Ultimate V

ya i understand that format but how do i call the database

i made the database with Visual C#






Re: Visual C# Express Edition login form

ralph.

Your code could look like this:

Code Snippet

string connString =

"Data Source=ServerIP;Initial Catalog=DatabaseName;User ID=user;Password=password";

SqlConnection sqlConn = new SqlConnection(connString);

SqlCommand sqlCommand = new SqlCommand("Select Password FROM userTable WHERE BenutzerName='"+

userName+"';", sqlConn);

sqlConn.Open();

SqlDataReader sqlDr = sqlCommand.ExecuteReader();

while (sqlDr.Read())

{

if (password == sqlDr["Password"].ToString())

{

//login

}

else

//do not login






Re: Visual C# Express Edition login form

Ultimate V

ok so can you kinda explain how this all fits together so i understand whats going on




Re: Visual C# Express Edition login form

ehajj

Here's another way:

Code Snippet
string cString = "Persist Security Info=False;Integrated Security=SSPI;database=dbname;server=ServerName";
String sqlStmt = "Select * FROM [user] WHERE username='" + this.textBox1.Text + "' AND password='" + this.textBox2.Text + "' AND role = 'normal'";

SqlConnection sqlConn = new SqlConnection(cString);
SqlCommand sqlCmd = new SqlCommand(sqlStmt, sqlConn);

sqlCmd.Connection.Open();
SqlDataReader sqlReader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection);

if (sqlReader.Read())
{

do something
}
else
{
MessageBox.Show("Wrong Username/Password Combination");
}






Re: Visual C# Express Edition login form

Ultimate V

i want to us VS_Programmer's method of doing this but how do i call the database




Re: Visual C# Express Edition login form

VS_Programmer

They are doing it my way. Try it.



Re: Visual C# Express Edition login form

Ultimate V

ok ok i see now... thanks guys!!