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. General Programming
  3. Visual Basic
  4. Inserting rows from data grid

Inserting rows from data grid

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

    Hi all, I would like to insert all records found in my datagrid into my table. The following code works but then there are limitation. I am using a For next loop to insert the rows from teh grid. The problem is if there less than 21 records then VB throws this error: No row at index. Can some one help mewith this. Tnx Here is the code for Button_click Dim da As New OleDbDataAdapter() Dim da1 As New OleDbDataAdapter() da.SelectCommand = New OleDbCommand() da.SelectCommand.Connection = conn da1.SelectCommand = New OleDbCommand() da1.SelectCommand.Connection = conn If conn.State <> ConnectionState.Open Then conn.Open() da.SelectCommand.CommandText = "Delete from Test where rectp = 'SH' and pkey = '001'" da.SelectCommand.CommandType = CommandType.Text da.SelectCommand.ExecuteNonQuery() Dim Icount As Integer For Icount = 0 To 20 If DBgrid2.Item(Icount, 0) <> "null" And DBgrid2.Item(Icount, 1) <> "null" And DBgrid2.Item(Icount, 2) <> "null" And DBgrid2.Item(Icount, 3) <> "null" Then da1.SelectCommand.CommandText = "insert into Test values('SH','" & Format(vBcust, "0000000") + Format(vSeqno, "000") & "'," & Icount & ",'" & DBgrid2.Item(Icount, 0) & "','" & DBgrid2.Item(Icount, 2) & "','" & DBgrid2.Item(Icount, 3) & "')" da1.SelectCommand.CommandType = CommandType.Text da1.SelectCommand.ExecuteNonQuery() End If Next

    A 1 Reply Last reply
    0
    • A Anonymous

      Hi all, I would like to insert all records found in my datagrid into my table. The following code works but then there are limitation. I am using a For next loop to insert the rows from teh grid. The problem is if there less than 21 records then VB throws this error: No row at index. Can some one help mewith this. Tnx Here is the code for Button_click Dim da As New OleDbDataAdapter() Dim da1 As New OleDbDataAdapter() da.SelectCommand = New OleDbCommand() da.SelectCommand.Connection = conn da1.SelectCommand = New OleDbCommand() da1.SelectCommand.Connection = conn If conn.State <> ConnectionState.Open Then conn.Open() da.SelectCommand.CommandText = "Delete from Test where rectp = 'SH' and pkey = '001'" da.SelectCommand.CommandType = CommandType.Text da.SelectCommand.ExecuteNonQuery() Dim Icount As Integer For Icount = 0 To 20 If DBgrid2.Item(Icount, 0) <> "null" And DBgrid2.Item(Icount, 1) <> "null" And DBgrid2.Item(Icount, 2) <> "null" And DBgrid2.Item(Icount, 3) <> "null" Then da1.SelectCommand.CommandText = "insert into Test values('SH','" & Format(vBcust, "0000000") + Format(vSeqno, "000") & "'," & Icount & ",'" & DBgrid2.Item(Icount, 0) & "','" & DBgrid2.Item(Icount, 2) & "','" & DBgrid2.Item(Icount, 3) & "')" da1.SelectCommand.CommandType = CommandType.Text da1.SelectCommand.ExecuteNonQuery() End If Next

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      hi why don't u bind the table with datagrid like this datagrid.datasource=DATAADAPTERUSED datagrid.datamember=TABLENAME then u will only need this command to update ur table DATAADAPTERUSED.update(TABLENAME)

      P 1 Reply Last reply
      0
      • A Anonymous

        hi why don't u bind the table with datagrid like this datagrid.datasource=DATAADAPTERUSED datagrid.datamember=TABLENAME then u will only need this command to update ur table DATAADAPTERUSED.update(TABLENAME)

        P Offline
        P Offline
        Paps2
        wrote on last edited by
        #3

        I could not understand the solution. Can you pls explain in detail. Tnx

        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