select statement in sqlserver 2000
-
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 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 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()
Surely something like this is what you're after... sqlConn = new SqlConnection(sqlConnString); strCommandString = "SELECT Count(*) FROM table WHERE username = "+textbox1.text; sqlCmd = new SqlCommand(strCommandString); sqlConn.Open(); intCount = sqlCmd.ExecuteScalar(); sqlConn.Close(); int intCount; if (intCount > 0) responser.redirect(“loginsuccess.aspx”) else response.write(“invalid login.aspx”) Why are you using a data adapter? That is for use with DataSets. I think you wanted a datareader but the above code is a nicer and more efficient way of doing it. Execute Scaler whill get the value from the top row of returned results. Which in you case with the Count(*) command will only be one anyway. Hope this Helps :) PS - might I suggest you also take the users password ;) "Gödel proved that any formal system that defines the primitive recursive functions must be either incomplete or inconsistent. In particular one could not prove from within the system that the system itself was consistent even though the question could be formulated within the system."
-
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 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 guess the problem is here cishi_us wrote: sqlCmd = new SqlCommand(“select username,password from table where username=@textbox1.text”); sqlDataAdapter da = new SqlDataAdapter(); da= cmd.executeReader() you did not add a paramter to the params collection of the sql command p = new SqlParameter("@Text"); p.Value=TextBox1.Text; cmd.Parameters.Add(p);
-
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 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()
better use SPs. you code is not secure. I can enter "; delete from table" in the text box and your data are gone
-
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 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()
Your string concatenation in the SQL Select is incorrect. Use something like this currentSchedule = new OleDbCommand("INSERT INTO Suite_Schedule( SId, SName, P, S, C, RR, ProjectId, ScheduleTime, SStatus ) SELECT SId, SName, P, S, C, RR, ProjectId, '" + schedule.ScheduledTime.ToString("G") + "', 'Test' FROM Suite WHERE SId= "+ schedule.SID +" ",dbConnection); ---------- user9 A student knows little about a lot. A professor knows a lot about little. I know everything about nothing.