Click to See Complete Forum and Search --> : C# SQL server


pikkas
01-10-2011, 05:51 AM
hi, i m trying to make something like a login page with C# using VS 2010 and SQL server database. I am using the following code to get the password from the appropriate username but i get an error of Object reference not set to an instance of an object.
. here is the code:


String username = txtusername.Text;
String password = txtpass.Text;

String connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand();
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "Select password from Details WHERE username=' " + username + "'";

String pass=cmd.ExecuteScalar().ToString();
Console.WriteLine(pass);
conn.Close();


Any help please?

mmrcela
01-19-2011, 02:58 PM
Hi Pikkas,
I am currently looking for a Software Developer in Illinois for a full time permanent position at our company. Do you know of anyone that is looking to change companies?
I appreciate any leads, thank you.