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:
Any help please?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();


Reply With Quote
Bookmarks