select with where clause in Sqlserver2000
-
i am connecting with sqlserver database ,then i need to acces that user which is in my textbox ,but no user comming from it. code is as follows: sqlConnString="server= your server; database= ;user id=;password=;"; sqlConn = new SqlConnection(sqlConnString); sqlConn.Open(); sqlCmd = new SqlCommand(“select username,password from table where username=@textbox1.text”); sqlDataAdapter da = new SqlDataAdapter(); da= cmd.executeReader() If da.read() { responser.redirect(“loginsuccess.aspx”) } else { response.write(“invalid login.aspx”) } +++++++++++++++++++++++++++ error is this System.Data.SqlClient.SqlException: Must declare the variable '@TextBox1'. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) at System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) at ASP.UserInfo_aspx.Page_Load()
-
i am connecting with sqlserver database ,then i need to acces that user which is in my textbox ,but no user comming from it. code is as follows: sqlConnString="server= your server; database= ;user id=;password=;"; sqlConn = new SqlConnection(sqlConnString); sqlConn.Open(); sqlCmd = new SqlCommand(“select username,password from table where username=@textbox1.text”); sqlDataAdapter da = new SqlDataAdapter(); da= cmd.executeReader() If da.read() { responser.redirect(“loginsuccess.aspx”) } else { response.write(“invalid login.aspx”) } +++++++++++++++++++++++++++ error is this System.Data.SqlClient.SqlException: Must declare the variable '@TextBox1'. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) at System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) at ASP.UserInfo_aspx.Page_Load()
cishi_us wrote: Must declare the variable '@TextBox1' Read up on how to use the SqlParameter object. Also, just use "@TextBox1", not "@TextBox1.Text". Marc MyXaml Advanced Unit Testing YAPO