c# - Keep receiving Invalid column name 'Username' -
i had exact name in database yet still maintain getting error titled.
an exception of type 'system.data.sqlclient.sqlexception' occurred in system.data.dll not handled in user code
image link : http://i.imgur.com/tktvlfj.png
additional information: invalid column name 'username'.
protected void button1_click(object sender, eventargs e) { sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["eregistrationconnectionstring"].connectionstring); conn.open(); string checkuser = "select count(*)from employer username='" + textboxelusername.text + "'"; sqlcommand com = new sqlcommand(checkuser, conn); int temp = convert.toint32(com.executescalar().tostring()); conn.close(); if (temp == 1) { conn.open(); string checkpasswordquery = "select password employer username='" + textboxelusername.text + "'"; sqlcommand passcomm = new sqlcommand(checkpasswordquery, conn); string password = passcomm.executescalar().tostring().replace(" ",""); if (password == textboxloginpassword.text) { session["new"] = textboxelusername.text; response.write("password correct"); } else { response.write("password incorrect"); } } else { response.write("username incorrect"); } }
your sql invalid. forgot space between count(*)
, from
keyword. seek instead:
select count(*) employer username=
also should alter sql not allow sql injections , utilize parameters
object
c# sql sql-server
No comments:
Post a Comment