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. How to Save changes in DataGridView into Database programmatically without using DataGridView Wizard

How to Save changes in DataGridView into Database programmatically without using DataGridView Wizard

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

    How to Save record or row changes in DataGridView directly into Database programmatically without using DataGridView Wizard or using an button events like btnSave_Click??? Anybody please help... I'm having difficulty with this problem... Here's my code how to fill records into DataGridview this works ok but i dont know how to save or update the new changes of the record inside this DataGridView Directly into database anyone can help me please??? please note: im using an MS ACCESS as database ************************ Private Sub LoadRecord(ByVal strSQL As String) Try 'open the connection oleConnection.ConnectionString = dbConnectionString oleConnection.Open() oleDataAdapter = New OleDbDataAdapter(strSQL, oleConnection) dbDataTable = New DataTable() dbBindingSource = New BindingSource oleDataAdapter.Fill(dbDataTable) dbBindingSource.DataSource = dbDataTable 'bind datagrid to BindingSource dgDailyTimeRecord.DataSource = dbBindingSource Catch ex As Exception MsgBox(ex.ToString()) Finally oleConnection.Close() End Try End Sub ****************************

    R 1 Reply Last reply
    0
    • V vbDiggerz

      How to Save record or row changes in DataGridView directly into Database programmatically without using DataGridView Wizard or using an button events like btnSave_Click??? Anybody please help... I'm having difficulty with this problem... Here's my code how to fill records into DataGridview this works ok but i dont know how to save or update the new changes of the record inside this DataGridView Directly into database anyone can help me please??? please note: im using an MS ACCESS as database ************************ Private Sub LoadRecord(ByVal strSQL As String) Try 'open the connection oleConnection.ConnectionString = dbConnectionString oleConnection.Open() oleDataAdapter = New OleDbDataAdapter(strSQL, oleConnection) dbDataTable = New DataTable() dbBindingSource = New BindingSource oleDataAdapter.Fill(dbDataTable) dbBindingSource.DataSource = dbDataTable 'bind datagrid to BindingSource dgDailyTimeRecord.DataSource = dbBindingSource Catch ex As Exception MsgBox(ex.ToString()) Finally oleConnection.Close() End Try End Sub ****************************

      R Offline
      R Offline
      rohitsrivastava
      wrote on last edited by
      #2

      see this only u want to save the data grid this is the code objsqlcon=new sqlconnection("user id=sa;password=;initial catalog=databasename;data source=servername") objsqlcon.open dim i as integer for i=0 to datagridview1.rowcount-1 strinsert="insert into tablename(fieldname1,fieldname2) values('" & datgridview1.cell(columnname1).rows(i)(0).value & "',"' & datgridview1.cell(columnname1).rows(i)(0).value & "')" objsqlcmd=new sqlcommand(strinsert,objsqlcon) objsqlcmd.executenonquery() next messagebox.show("Record Successfully Saved ")

      V 1 Reply Last reply
      0
      • R rohitsrivastava

        see this only u want to save the data grid this is the code objsqlcon=new sqlconnection("user id=sa;password=;initial catalog=databasename;data source=servername") objsqlcon.open dim i as integer for i=0 to datagridview1.rowcount-1 strinsert="insert into tablename(fieldname1,fieldname2) values('" & datgridview1.cell(columnname1).rows(i)(0).value & "',"' & datgridview1.cell(columnname1).rows(i)(0).value & "')" objsqlcmd=new sqlcommand(strinsert,objsqlcon) objsqlcmd.executenonquery() next messagebox.show("Record Successfully Saved ")

        V Offline
        V Offline
        vbDiggerz
        wrote on last edited by
        #3

        thanks for the reply... i appreciate that... your connection is SQLConnection Type so i've a little convertion as OleDBConnection type because im using an .MDB database.. ******************** Dim strinsert As String oleConnection.ConnectionString = dbConnectionString oleConnection.Open() Dim i As Integer For i = 0 To dgDailyTimeRecord.RowCount - 1 strinsert = "insert into tablename(fieldname1,fieldname2) values('" & dgvDailyTimeRecord.rows(i).cell(0).value & "', '" & dgvDailyTimeRecord.rows(i).cell(0).value & "')" oleCommand = New OleDbCommand(strinsert, oleConnection) oleCommand.ExecuteNonQuery() Next MessageBox.Show("Record Successfully Saved ") ******************** Thank you so much...

        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