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. from a textbox to Excel

from a textbox to Excel

Scheduled Pinned Locked Moved Visual Basic
help
6 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.
  • D Offline
    D Offline
    DawgTagz
    wrote on last edited by
    #1

    Hello, I am tring to create a program to help my work schedual Pull Stock. I have a problem getting the value of the variables into a spreadsheet. This is some test code I am trying to get to work: Public Sub Insertdata() 'Insert data typed in txt boxes into ExcelData1.xls Dim conn1 As New System.Data.OleDb.OleDbConnection(m_sConn1) conn1.Open() Dim cmd As New System.Data.OleDb.OleDbCommand() Dim strID As String Dim strName As String Dim Birthdate As Date strID = txtID.Text strName = txtName.Text Birthdate = txtBirthdate.Text cmd.Connection = conn1 '******Here is where the trouble is*********************** cmd.CommandText = "INSERT INTO [EmployeeData$] (ID, Name, BirthDate) values (strID, strName, Birthdate)" '****** the values of:(strID, strName, Birthdate)will not pass********** cmd.ExecuteNonQuery() conn1.Close() End Sub Any advice would be greatly appreciated Thanks!

    D 1 Reply Last reply
    0
    • D DawgTagz

      Hello, I am tring to create a program to help my work schedual Pull Stock. I have a problem getting the value of the variables into a spreadsheet. This is some test code I am trying to get to work: Public Sub Insertdata() 'Insert data typed in txt boxes into ExcelData1.xls Dim conn1 As New System.Data.OleDb.OleDbConnection(m_sConn1) conn1.Open() Dim cmd As New System.Data.OleDb.OleDbCommand() Dim strID As String Dim strName As String Dim Birthdate As Date strID = txtID.Text strName = txtName.Text Birthdate = txtBirthdate.Text cmd.Connection = conn1 '******Here is where the trouble is*********************** cmd.CommandText = "INSERT INTO [EmployeeData$] (ID, Name, BirthDate) values (strID, strName, Birthdate)" '****** the values of:(strID, strName, Birthdate)will not pass********** cmd.ExecuteNonQuery() conn1.Close() End Sub Any advice would be greatly appreciated Thanks!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      DawgTagz wrote: '******Here is where the trouble is*********************** cmd.CommandText = "INSERT INTO [EmployeeData$] (ID, Name, BirthDate) values (strID, strName, Birthdate)" You might want to try this instead:

      cmd.CommandText = "INSERT INTO [EmployeeData$] (ID, Name, BirthDate) values (" & strID & "," & strName & "," & Birthdate & ")"

      That way, you're passing the actual values of strID, strName, and Birthdate instead of the text string "strID, strName, Birthdate". RageInTheMachine9532

      D 2 Replies Last reply
      0
      • D Dave Kreskowiak

        DawgTagz wrote: '******Here is where the trouble is*********************** cmd.CommandText = "INSERT INTO [EmployeeData$] (ID, Name, BirthDate) values (strID, strName, Birthdate)" You might want to try this instead:

        cmd.CommandText = "INSERT INTO [EmployeeData$] (ID, Name, BirthDate) values (" & strID & "," & strName & "," & Birthdate & ")"

        That way, you're passing the actual values of strID, strName, and Birthdate instead of the text string "strID, strName, Birthdate". RageInTheMachine9532

        D Offline
        D Offline
        DawgTagz
        wrote on last edited by
        #3

        Thanks! I will try that tonight.

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          DawgTagz wrote: '******Here is where the trouble is*********************** cmd.CommandText = "INSERT INTO [EmployeeData$] (ID, Name, BirthDate) values (strID, strName, Birthdate)" You might want to try this instead:

          cmd.CommandText = "INSERT INTO [EmployeeData$] (ID, Name, BirthDate) values (" & strID & "," & strName & "," & Birthdate & ")"

          That way, you're passing the actual values of strID, strName, and Birthdate instead of the text string "strID, strName, Birthdate". RageInTheMachine9532

          D Offline
          D Offline
          DawgTagz
          wrote on last edited by
          #4

          Nope, That didn't work. I keep getting: "No value given for one or more parameters."

          D 1 Reply Last reply
          0
          • D DawgTagz

            Nope, That didn't work. I keep getting: "No value given for one or more parameters."

            D Offline
            D Offline
            DawgTagz
            wrote on last edited by
            #5

            Even when I try passing the actual value of the textBox instead of the variables.

            D 1 Reply Last reply
            0
            • D DawgTagz

              Even when I try passing the actual value of the textBox instead of the variables.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              In that case, it's the SQL INSERT statement that is bad or not formated correctly. After looking up the INSERT statement on MSDN, I've found that it should look something like this:

              cmd.CommandText = "INSERT INTO [EmployeeData$] (ID, Name, BirthDate) values ('" & strID & "', '" & strName & "', #" & Birthdate & "#)"

              Where string values must be enclosed in single quotes. Date values must be passed something like #1/1/1999# (enclosed in pound signs). I haven't tested this, but it should work according to the docs. ;) You might have to make sure that the Birthdate gets passed in the correct format. RageInTheMachine9532

              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