Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. select statement in sqlserver 2000

select statement in sqlserver 2000

Scheduled Pinned Locked Moved ASP.NET
databasesysadminhelp
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cishi_us
    wrote on last edited by
    #1

    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()

    S N D 4 Replies Last reply
    0
    • C cishi_us

      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()

      S Offline
      S Offline
      Stephen Adam
      wrote on last edited by
      #2

      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."

      1 Reply Last reply
      0
      • C cishi_us

        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()

        N Offline
        N Offline
        NewSilence
        wrote on last edited by
        #3

        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);

        1 Reply Last reply
        0
        • C cishi_us

          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()

          N Offline
          N Offline
          NewSilence
          wrote on last edited by
          #4

          better use SPs. you code is not secure. I can enter "; delete from table" in the text box and your data are gone

          1 Reply Last reply
          0
          • C cishi_us

            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()

            D Offline
            D Offline
            DELETEUSER
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups