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. DataReader & Placeholder

DataReader & Placeholder

Scheduled Pinned Locked Moved ASP.NET
databasesql-servervisual-studiosysadminhelp
6 Posts 3 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
    comp_j
    wrote on last edited by
    #1

    Hello Im using: SQL Server 2005 - VS 2008 Im trying to read data with using DataReader. when I want to replace my data with variable there is an error : Must declare the scalar variable "@G#". Behind code : objConnection.Open(); string query = "Select * From goods where G#=@G#"; objDataAdapter.SelectCommand.Parameters.AddWithValue("@G",Textbox.Text); using (reader = new SqlCommand(query, objConnection).ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { // Do sth } } } TIA :)

    A A 2 Replies Last reply
    0
    • C comp_j

      Hello Im using: SQL Server 2005 - VS 2008 Im trying to read data with using DataReader. when I want to replace my data with variable there is an error : Must declare the scalar variable "@G#". Behind code : objConnection.Open(); string query = "Select * From goods where G#=@G#"; objDataAdapter.SelectCommand.Parameters.AddWithValue("@G",Textbox.Text); using (reader = new SqlCommand(query, objConnection).ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { // Do sth } } } TIA :)

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      comp_j wrote:

      string query = "Select * From goods where G#=@G#";

      What was that ? G# is your field name ?

      comp_j wrote:

      @G#"

      You can't use over here. You need to used '@' when you are using parameter only.

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

      C 1 Reply Last reply
      0
      • A Abhijit Jana

        comp_j wrote:

        string query = "Select * From goods where G#=@G#";

        What was that ? G# is your field name ?

        comp_j wrote:

        @G#"

        You can't use over here. You need to used '@' when you are using parameter only.

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

        C Offline
        C Offline
        comp_j
        wrote on last edited by
        #3

        Yes, it is my field name.

        Abhijit Jana wrote:

        You can't use over here. You need to used '@' when you are using parameter only.

        I didnt understand what you said. plz explain it with a sample code.

        1 Reply Last reply
        0
        • C comp_j

          Hello Im using: SQL Server 2005 - VS 2008 Im trying to read data with using DataReader. when I want to replace my data with variable there is an error : Must declare the scalar variable "@G#". Behind code : objConnection.Open(); string query = "Select * From goods where G#=@G#"; objDataAdapter.SelectCommand.Parameters.AddWithValue("@G",Textbox.Text); using (reader = new SqlCommand(query, objConnection).ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { // Do sth } } } TIA :)

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          using(SqlConnection objConnection = new SqlConnection) { objConnection.Open(); string query = "Select * From goods where G#=@GParam"; using (SqlCommand command = new SqlCommand(query, objConnection)) { command.Parameters.Add(new SqlParameter("@GParam", SqlDataType.yourtype, value)); // Do replace with your value here. SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { // Do sth } } } } Hope this works... :rose::rose:

          Abhishek Sur


          My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

          **Don't forget to click "Good Answer" if you like the post

          C 1 Reply Last reply
          0
          • A Abhishek Sur

            using(SqlConnection objConnection = new SqlConnection) { objConnection.Open(); string query = "Select * From goods where G#=@GParam"; using (SqlCommand command = new SqlCommand(query, objConnection)) { command.Parameters.Add(new SqlParameter("@GParam", SqlDataType.yourtype, value)); // Do replace with your value here. SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { // Do sth } } } } Hope this works... :rose::rose:

            Abhishek Sur


            My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

            **Don't forget to click "Good Answer" if you like the post

            C Offline
            C Offline
            comp_j
            wrote on last edited by
            #5

            It worked :thumbsup: Thank you so much. :rose::rose:

            A 1 Reply Last reply
            0
            • C comp_j

              It worked :thumbsup: Thank you so much. :rose::rose:

              A Offline
              A Offline
              Abhishek Sur
              wrote on last edited by
              #6

              you are most welcome friend. :thumbsup::thumbsup:

              Abhishek Sur


              My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

              **Don't forget to click "Good Answer" if you like t

              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