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. Database & SysAdmin
  3. Database
  4. C# SQL INSERT String???

C# SQL INSERT String???

Scheduled Pinned Locked Moved Database
helpregexcsharpdatabasequestion
4 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.
  • G Offline
    G Offline
    gman44
    wrote on last edited by
    #1

    I have a slight problem inserting the proper result into an MS-SQL table. The result should be <14> however all I get is PRE. BTW, the SQL command not broken appart like you see it on this limited width posting.......... I thought using single quotes desiganted a 'string'? Help........ string pattern1 = @"(<\d{2,3}>)"; Regex r1 = new Regex(pattern1, RegexOptions.Compiled); Match PRE = r1.Match(stringOfData); { try { connection1.Open(); SqlDataAdapter1.SelectCommand.CommandText = "INSERT INTO tblMyUdpServer (col_PRE) VALUES ('PRE')"; SqlDataAdapter1.SelectCommand.ExecuteNonQuery(); connection1.Close(); } catch(SqlException error) { MessageBox.Show(error.Message.ToString()); } listBox1.Items.Add(PRE.ToString()); } }

    C S 2 Replies Last reply
    0
    • G gman44

      I have a slight problem inserting the proper result into an MS-SQL table. The result should be <14> however all I get is PRE. BTW, the SQL command not broken appart like you see it on this limited width posting.......... I thought using single quotes desiganted a 'string'? Help........ string pattern1 = @"(<\d{2,3}>)"; Regex r1 = new Regex(pattern1, RegexOptions.Compiled); Match PRE = r1.Match(stringOfData); { try { connection1.Open(); SqlDataAdapter1.SelectCommand.CommandText = "INSERT INTO tblMyUdpServer (col_PRE) VALUES ('PRE')"; SqlDataAdapter1.SelectCommand.ExecuteNonQuery(); connection1.Close(); } catch(SqlException error) { MessageBox.Show(error.Message.ToString()); } listBox1.Items.Add(PRE.ToString()); } }

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

      Ummmm... Are you trying to say that the VALUES('PRE') in your CommandText is supposed to be the result of Match PRE = r1.Match(stringOfData) ???


      "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!

      G 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Ummmm... Are you trying to say that the VALUES('PRE') in your CommandText is supposed to be the result of Match PRE = r1.Match(stringOfData) ???


        "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!

        G Offline
        G Offline
        gman44
        wrote on last edited by
        #3

        Yes, this particular Regex matches numbers between < >. For instance <14>, however only PRE is written to the database........

        1 Reply Last reply
        0
        • G gman44

          I have a slight problem inserting the proper result into an MS-SQL table. The result should be <14> however all I get is PRE. BTW, the SQL command not broken appart like you see it on this limited width posting.......... I thought using single quotes desiganted a 'string'? Help........ string pattern1 = @"(<\d{2,3}>)"; Regex r1 = new Regex(pattern1, RegexOptions.Compiled); Match PRE = r1.Match(stringOfData); { try { connection1.Open(); SqlDataAdapter1.SelectCommand.CommandText = "INSERT INTO tblMyUdpServer (col_PRE) VALUES ('PRE')"; SqlDataAdapter1.SelectCommand.ExecuteNonQuery(); connection1.Close(); } catch(SqlException error) { MessageBox.Show(error.Message.ToString()); } listBox1.Items.Add(PRE.ToString()); } }

          S Offline
          S Offline
          S Sansanwal
          wrote on last edited by
          #4

          You are inserting hardCoded "PRE" value rather than variable PRE Change your sql to SqlDataAdapter1.SelectCommand.CommandText = "INSERT INTO tblMyUdpServer (col_PRE) VALUES (" + PRE.Value + ")"; Sanjay Sansanwal www.sansanwal.com

          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