I am a beginner and would like to implement basic login page using C#.net - web application. I have created database successfully and can test connection worked as well. I get the below error message when the control hits ExecuteReader() command.
Error:
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: Invalid object name 'UserDB'.
Program:
string LoginDbCS =ConfigurationManager.ConnectionStrings["UserDB"].ConnectionString; string ID = TextBoxUserId.Text; SqlConnection Conn = new SqlConnection(LoginDbCS); { string sCmdStr = "select Password from UserDB where UserID=@ID"; SqlCommand sCmd = new SqlCommand(sCmdStr, Conn); SqlParameter param = new SqlParameter(); param.ParameterName = "@ID"; param.Value = TextBoxUserId.Text; sCmd.Parameters.Add(param); Conn.Open(); SqlDataReader sReader = sCmd.ExecuteReader(); sReader.Read(); if ((string)sReader["Password"]==TextBoxPassword.Text) { Label5.Text = "Login Successful"; } else { Label5.Text = "No Records found"; } sReader.Close(); Conn.Close(); } }
Looking forward for suggestions to fix this crash.
UserDBtable belongs?UserDB. I guessUserDBis your Database name.. You have to select records from a table of your DatabaseUserDBis present or not..