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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Updating SQL Server 2000 with varying column names

Updating SQL Server 2000 with varying column names

Scheduled Pinned Locked Moved Database
helpdatabasesql-serversysadmindiscussion
3 Posts 2 Posters 2 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
    ColdWaterBlue
    wrote on last edited by
    #1

    I am trying to update a table in SQL Server 2000 that will be able to have varying column names (based on the user's specifications). I can read the data fine, but I can't add anything to the table. There are spaces in the column name (i.e. "Received By") and when reading I put brackets [] around it and it works. When I am trying to write to the table, I can update the dataset fine, but not the table in SQL Server. I believe it is a problem with my parameter declaration. When I try to save the data, I get the following error: Line 1: Incorrect syntax near 'varchar'. My code is as follows (not everything because it is quite lengthy): Dim custom01 As String 'Contains the name of the column/field Dim sampleTable As String 'Contains the name of the table within SQL Server sampleUpdate = New SqlClient.SqlCommand("UPDATE " & sampleTable & " SET " & custom01 & " = @" & custom01, dataConnect) With sampleUpdate With .Parameters .Add("@" & custom01, SqlDbType.Varchar, 50, custom01) End With End With As I said, I can update the dataset fine, but when I try to up the dataset back into SQL Server, it crashes. Any thoughts would be greatly appreciated.

    L 1 Reply Last reply
    0
    • C ColdWaterBlue

      I am trying to update a table in SQL Server 2000 that will be able to have varying column names (based on the user's specifications). I can read the data fine, but I can't add anything to the table. There are spaces in the column name (i.e. "Received By") and when reading I put brackets [] around it and it works. When I am trying to write to the table, I can update the dataset fine, but not the table in SQL Server. I believe it is a problem with my parameter declaration. When I try to save the data, I get the following error: Line 1: Incorrect syntax near 'varchar'. My code is as follows (not everything because it is quite lengthy): Dim custom01 As String 'Contains the name of the column/field Dim sampleTable As String 'Contains the name of the table within SQL Server sampleUpdate = New SqlClient.SqlCommand("UPDATE " & sampleTable & " SET " & custom01 & " = @" & custom01, dataConnect) With sampleUpdate With .Parameters .Add("@" & custom01, SqlDbType.Varchar, 50, custom01) End With End With As I said, I can update the dataset fine, but when I try to up the dataset back into SQL Server, it crashes. Any thoughts would be greatly appreciated.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      ColdWaterBlue wrote: Dim sampleTable As String 'Contains the name of the table within SQL Server sampleUpdate = New SqlClient.SqlCommand("UPDATE " & sampleTable & " SET " & custom01 & " = @" & custom01, dataConnect) Where is the name of your table? You declare a string to hold the table but you did not give any table name to that string variable (according to the code). So your sampleTable variable would contain "". Try to give your table name and to the sampleTable variable before process the query.


      A thousand mile of journey, begin with the first step. APO-CEDC Save Children Norway-Cambodia Office

      C 1 Reply Last reply
      0
      • L Lost User

        ColdWaterBlue wrote: Dim sampleTable As String 'Contains the name of the table within SQL Server sampleUpdate = New SqlClient.SqlCommand("UPDATE " & sampleTable & " SET " & custom01 & " = @" & custom01, dataConnect) Where is the name of your table? You declare a string to hold the table but you did not give any table name to that string variable (according to the code). So your sampleTable variable would contain "". Try to give your table name and to the sampleTable variable before process the query.


        A thousand mile of journey, begin with the first step. APO-CEDC Save Children Norway-Cambodia Office

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

        For simplicity's sake, I did not include most of the code. The "sampleTable" variable is actually a global variable that houses the table name, but I included the Dim statement to show that it was a variable.

        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