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. General Programming
  3. Visual Basic
  4. In Code Behind, What is proper select statement syntax to retrieve the @BName field from a table?

In Code Behind, What is proper select statement syntax to retrieve the @BName field from a table?

Scheduled Pinned Locked Moved Visual Basic
databasequestioncsharpsql-servervisual-studio
3 Posts 2 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.
  • K Offline
    K Offline
    kenn_rosie
    wrote on last edited by
    #1

    In Code Behind, What is proper select statement syntax to retrieve the @BName field from a table? Using Visual Studio 2003 SQL Server DB I created the following parameter: Dim strName As String Dim parameterBName As SqlParameter = New SqlParameter("@BName", SqlDbType.VarChar, 50) parameterBName.Value = strName myCommand.Parameters.Add(parameterBName) I tried the following but get error: Dim strSql As String = "select @BName from Borrower where BName= DOROTHY V FOWLER " error is: Line 1: Incorrect syntax near 'V'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'V'. Source Error: Line 59: Line 60: Line 61: myCommand.ExecuteNonQuery() 'Execute the query

    K 1 Reply Last reply
    0
    • K kenn_rosie

      In Code Behind, What is proper select statement syntax to retrieve the @BName field from a table? Using Visual Studio 2003 SQL Server DB I created the following parameter: Dim strName As String Dim parameterBName As SqlParameter = New SqlParameter("@BName", SqlDbType.VarChar, 50) parameterBName.Value = strName myCommand.Parameters.Add(parameterBName) I tried the following but get error: Dim strSql As String = "select @BName from Borrower where BName= DOROTHY V FOWLER " error is: Line 1: Incorrect syntax near 'V'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'V'. Source Error: Line 59: Line 60: Line 61: myCommand.ExecuteNonQuery() 'Execute the query

      K Offline
      K Offline
      kenn_rosie
      wrote on last edited by
      #2

      Sorry: To further clarify My database table name is borrower and two of the fields are BName and TaxID, I am trying to select a particular borrower (BName) with a taxid OF 767, lets say in this case THE BORROWER IS Bill Jones I declared the following variables: Dim strName As String Dim parameterBName As SqlParameter = New SqlParameter("@BName", SqlDbType.VarChar, 50) parameterBName.Value = strName myCommand.Parameters.Add(parameterBName) Dim strTaxID As String Dim ParameterTaxID As SqlParameter = New SqlParameter("@TaxID", SqlDbType.VarChar, 15) ParameterTaxID.Value = strTaxID myCommand.Parameters.Add(ParameterTaxID) I inserted the folowing command: Dim strSql As String = "select BName from Borrower where TaxID= @333-00-1492 " I get error: Must declare the variable '@333'.

      C 1 Reply Last reply
      0
      • K kenn_rosie

        Sorry: To further clarify My database table name is borrower and two of the fields are BName and TaxID, I am trying to select a particular borrower (BName) with a taxid OF 767, lets say in this case THE BORROWER IS Bill Jones I declared the following variables: Dim strName As String Dim parameterBName As SqlParameter = New SqlParameter("@BName", SqlDbType.VarChar, 50) parameterBName.Value = strName myCommand.Parameters.Add(parameterBName) Dim strTaxID As String Dim ParameterTaxID As SqlParameter = New SqlParameter("@TaxID", SqlDbType.VarChar, 15) ParameterTaxID.Value = strTaxID myCommand.Parameters.Add(ParameterTaxID) I inserted the folowing command: Dim strSql As String = "select BName from Borrower where TaxID= @333-00-1492 " I get error: Must declare the variable '@333'.

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        You pass in two parameters but you don't use them in the SQL statement. You then use a parameter (@333) that does not exist. Maybe somthing like this would work:

        SELECT BName from Borrower WHERE TaxID = @TaxID

        You can drop the parameter @BName as it is not being used. To get the BName back into your application you can use ExecuteScalar().


        "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

        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