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. How to get record by using ID

How to get record by using ID

Scheduled Pinned Locked Moved ASP.NET
helpdatabasetutorial
8 Posts 6 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.
  • S Offline
    S Offline
    slSoftware
    wrote on last edited by
    #1

    I have created a web form,but i have small problem,i need to retreive records from database according to ID which i given in the form in text box,i have created the StoredProcedure for that one its retreive data and i put where fieldname=@ID. When i'm using datagrid or GridView this will not occour,but i need to do in using text box.Please help me to do this Thank You

    C V 2 Replies Last reply
    0
    • S slSoftware

      I have created a web form,but i have small problem,i need to retreive records from database according to ID which i given in the form in text box,i have created the StoredProcedure for that one its retreive data and i put where fieldname=@ID. When i'm using datagrid or GridView this will not occour,but i need to do in using text box.Please help me to do this Thank You

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      What is the question ? You need to write the SQL, which is basically select * from tbl where fieldname = id.  Sounds like you did that.  So, you get the id from the textbox, and pass it to the proc, set your datasource with the result, and databind.

      Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

      S 1 Reply Last reply
      0
      • C Christian Graus

        What is the question ? You need to write the SQL, which is basically select * from tbl where fieldname = id.  Sounds like you did that.  So, you get the id from the textbox, and pass it to the proc, set your datasource with the result, and databind.

        Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

        S Offline
        S Offline
        slSoftware
        wrote on last edited by
        #3

        Ok but how do i pass my text value into StoredProcedure and i'm using DataReaders. Note-:Can i use SqlParameter for this one,if yes,how to do that.

        K 1 Reply Last reply
        0
        • S slSoftware

          I have created a web form,but i have small problem,i need to retreive records from database according to ID which i given in the form in text box,i have created the StoredProcedure for that one its retreive data and i put where fieldname=@ID. When i'm using datagrid or GridView this will not occour,but i need to do in using text box.Please help me to do this Thank You

          V Offline
          V Offline
          Vinay Dornala
          wrote on last edited by
          #4

          Hi, first write one storedProc for Select data from DB with ID, Here is the Stored Procedure . Create Procedure nameofStoredProcedure ( @ID ) AS select * from table where id=@ID ADO.NEt code SqlConnection Con=new SqlConnection("userid="";databse=""; password=""); con.Open(); SqlCommand cmd=new SqlCommand("nameofStroredProcedure",con); cmd.CommandType=CommandType.StoredProcedure; cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10)); cmd.parameter[0].value=textbox1.text; SqlDataAdapter da=new SqlDataAdapter(); da.selectCommand=cmd; da.fill(ds,"tablename"); con.Close(); i hope this will helpful for u, try onces. WINNING IS NOT OUR DREAM,IT'S A HABIT HAVE A NICE DAY

          J S 2 Replies Last reply
          0
          • S slSoftware

            Ok but how do i pass my text value into StoredProcedure and i'm using DataReaders. Note-:Can i use SqlParameter for this one,if yes,how to do that.

            K Offline
            K Offline
            kiran kumar Intelligroup
            wrote on last edited by
            #5

            SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@", SqlDbType.NVarChar, 50); param[0].Direction == ParameterDirection.InputOutput; param[0].Value=; //Add the parameters to the command object objcommand.Parameters.Add(param); objcommand.CommandType=CommandType.StoreProcedure; objcommand.Connection=; objcommand.Command="Stored Proc Name"; objcommand.ExecuteNonQuery();

            Kiran Kumar.CH (MCP)

            1 Reply Last reply
            0
            • V Vinay Dornala

              Hi, first write one storedProc for Select data from DB with ID, Here is the Stored Procedure . Create Procedure nameofStoredProcedure ( @ID ) AS select * from table where id=@ID ADO.NEt code SqlConnection Con=new SqlConnection("userid="";databse=""; password=""); con.Open(); SqlCommand cmd=new SqlCommand("nameofStroredProcedure",con); cmd.CommandType=CommandType.StoredProcedure; cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10)); cmd.parameter[0].value=textbox1.text; SqlDataAdapter da=new SqlDataAdapter(); da.selectCommand=cmd; da.fill(ds,"tablename"); con.Close(); i hope this will helpful for u, try onces. WINNING IS NOT OUR DREAM,IT'S A HABIT HAVE A NICE DAY

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #6

              dornala wrote:

              Create Procedure nameofStoredProcedure ( @ID )

              Incorrect syntax - you need to specify the datatype

              dornala wrote:

              SqlConnection Con=new SqlConnection("userid="";databse=""; password="");

              Incorrect syntax - check your quotes

              dornala wrote:

              cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10));

              Incorrect syntax - it should be cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.VarChar,10));

              --- How to get answers to your questions[^]

              S 1 Reply Last reply
              0
              • J J4amieC

                dornala wrote:

                Create Procedure nameofStoredProcedure ( @ID )

                Incorrect syntax - you need to specify the datatype

                dornala wrote:

                SqlConnection Con=new SqlConnection("userid="";databse=""; password="");

                Incorrect syntax - check your quotes

                dornala wrote:

                cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10));

                Incorrect syntax - it should be cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.VarChar,10));

                --- How to get answers to your questions[^]

                S Offline
                S Offline
                szukuro
                wrote on last edited by
                #7

                J4amieC wrote:

                Incorrect syntax - it should be cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.VarChar,10));

                Well actually it should be cmd.Parameters.Add(new SqlParameter("@ID",SqlDbType.VarChar,10)); :P Also instead of using cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10)); cmd.parameter[0].value=textbox1.text; as described in the previous post, it would be much easier to use: cmd.Parameters.Add("@ID", textbox1.Text); (AddWithValue in 2.0) Just my daily cup of being a smartass.

                1 Reply Last reply
                0
                • V Vinay Dornala

                  Hi, first write one storedProc for Select data from DB with ID, Here is the Stored Procedure . Create Procedure nameofStoredProcedure ( @ID ) AS select * from table where id=@ID ADO.NEt code SqlConnection Con=new SqlConnection("userid="";databse=""; password=""); con.Open(); SqlCommand cmd=new SqlCommand("nameofStroredProcedure",con); cmd.CommandType=CommandType.StoredProcedure; cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10)); cmd.parameter[0].value=textbox1.text; SqlDataAdapter da=new SqlDataAdapter(); da.selectCommand=cmd; da.fill(ds,"tablename"); con.Close(); i hope this will helpful for u, try onces. WINNING IS NOT OUR DREAM,IT'S A HABIT HAVE A NICE DAY

                  S Offline
                  S Offline
                  slSoftware
                  wrote on last edited by
                  #8

                  Hi Thank you freind Its working fine.

                  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