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. Could I have some help with Sql statement.

Could I have some help with Sql statement.

Scheduled Pinned Locked Moved Visual Basic
helpdatabasequestion
7 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.
  • M Offline
    M Offline
    MickYL
    wrote on last edited by
    #1

    This gives me an error and I've tried changing the values and formats within the brackets. Dim strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim Sql As String = "Insert into tblTransaction values(#12/05/06#,1,1,100,'this is it')" Dim Sql2 As String = "Insert into tblTransaction values()" Dim conn As New OleDbConnection(strconn) Dim cmd As New OleDbCommand(Sql, conn) conn.Open() cmd.ExecuteNonQuery() Is this pretty far off how you do an insert statement ?

    G M 2 Replies Last reply
    0
    • M MickYL

      This gives me an error and I've tried changing the values and formats within the brackets. Dim strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim Sql As String = "Insert into tblTransaction values(#12/05/06#,1,1,100,'this is it')" Dim Sql2 As String = "Insert into tblTransaction values()" Dim conn As New OleDbConnection(strconn) Dim cmd As New OleDbCommand(Sql, conn) conn.Open() cmd.ExecuteNonQuery() Is this pretty far off how you do an insert statement ?

      G Offline
      G Offline
      Guerven
      wrote on last edited by
      #2

      have you tried inserting the fields? "Insert into tblTransaction values(#12/05/06#,1,1,100,'this is it')7" "Insert into tblTransaction (field1,field2 ....) values(#12/05/06#,1,1,100,'this is it')7"

      GUERVEN Truth or Consequence

      M 1 Reply Last reply
      0
      • G Guerven

        have you tried inserting the fields? "Insert into tblTransaction values(#12/05/06#,1,1,100,'this is it')7" "Insert into tblTransaction (field1,field2 ....) values(#12/05/06#,1,1,100,'this is it')7"

        GUERVEN Truth or Consequence

        M Offline
        M Offline
        MickYL
        wrote on last edited by
        #3

        what is the 7 about ?

        C 1 Reply Last reply
        0
        • M MickYL

          This gives me an error and I've tried changing the values and formats within the brackets. Dim strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim Sql As String = "Insert into tblTransaction values(#12/05/06#,1,1,100,'this is it')" Dim Sql2 As String = "Insert into tblTransaction values()" Dim conn As New OleDbConnection(strconn) Dim cmd As New OleDbCommand(Sql, conn) conn.Open() cmd.ExecuteNonQuery() Is this pretty far off how you do an insert statement ?

          M Offline
          M Offline
          MickYL
          wrote on last edited by
          #4

          Also the newrow statement falls over with "null reference" when I code the dataadapter but not when I add in a dataadapter from the wizard. So what should the sql be here ? or the command so that I can creat a new row ? Dim strConn As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim conn As New OleDbConnection(strConn) Dim Sql As String = "select * from tblTransaction" Dim adapter As OleDbDataAdapter adapter = New OleDbDataAdapter(Sql, conn) Dim ds As New DataSet Dim intc As Integer Dim str As String intc = adapter.Fill(ds) ' str = ds.Tables(0).Rows(0).Item(4) Me.Text = str Dim newrow As DataRow = ds.Tables("tblTransaction").NewRow Please if you can help ? ml -- modified at 5:24 Thursday 27th July, 2006

          C G 2 Replies Last reply
          0
          • M MickYL

            what is the 7 about ?

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

            typo


            Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

            1 Reply Last reply
            0
            • M MickYL

              Also the newrow statement falls over with "null reference" when I code the dataadapter but not when I add in a dataadapter from the wizard. So what should the sql be here ? or the command so that I can creat a new row ? Dim strConn As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim conn As New OleDbConnection(strConn) Dim Sql As String = "select * from tblTransaction" Dim adapter As OleDbDataAdapter adapter = New OleDbDataAdapter(Sql, conn) Dim ds As New DataSet Dim intc As Integer Dim str As String intc = adapter.Fill(ds) ' str = ds.Tables(0).Rows(0).Item(4) Me.Text = str Dim newrow As DataRow = ds.Tables("tblTransaction").NewRow Please if you can help ? ml -- modified at 5:24 Thursday 27th July, 2006

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

              You didn't tell the DataSet what the name of the tables are. Try: ds.Tables(0).NewRow


              Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

              1 Reply Last reply
              0
              • M MickYL

                Also the newrow statement falls over with "null reference" when I code the dataadapter but not when I add in a dataadapter from the wizard. So what should the sql be here ? or the command so that I can creat a new row ? Dim strConn As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim conn As New OleDbConnection(strConn) Dim Sql As String = "select * from tblTransaction" Dim adapter As OleDbDataAdapter adapter = New OleDbDataAdapter(Sql, conn) Dim ds As New DataSet Dim intc As Integer Dim str As String intc = adapter.Fill(ds) ' str = ds.Tables(0).Rows(0).Item(4) Me.Text = str Dim newrow As DataRow = ds.Tables("tblTransaction").NewRow Please if you can help ? ml -- modified at 5:24 Thursday 27th July, 2006

                G Offline
                G Offline
                Guerven
                wrote on last edited by
                #7

                HI. from the flow of the code I assume you want to fill a datatable and then create a new row from it. you can directly fill a datatable without using a dataset. Here I replaced some of the code. With this method, you have a direct access to the dattable. Dim strConn As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb" Dim conn As New OleDbConnection(strConn) Dim Sql As String = "select * from tblTransaction" Dim TblTrans as new datatable Dim adapter As OleDbDataAdapter adapter = New OleDbDataAdapter(Sql, conn) conn.open() intc = adapter.Fill(TBLtrans) Dim newrow As DataRow = TBLtrans.NewRow furthermore, you can filter the datatable using its defaultview without using an extra dataview. TblTrans.DefaultView.RowStateFilter=DataViewRowState.Added Datagrid1.datasource = TBLtrans.defaultview

                GUERVEN Truth or Consequence

                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