Hi again !!
I am making a widows application wherein i have a form containing two datagridviews..
The first one( named dgv1) consists of all the data from the database and a checkbox column..
While the user selects the rows using checkbox, the data are displayed in adjoining datagridview(named dgv3)..
Now, the issue is that when i click submit button, i want the data in dgv3 to be inserted in database (Ms access-2003)..
I have referred and tried various snippets, as per my understanding but in vain !! none working for me.. Can u plz help ??
I am using : vb.net, vs2008, ms access 2003..
Thank You !!
This is what i have done so far..
Public Class BOM
Inherits System.Windows.Forms.Form
Dim wrkdir As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location())
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim bs As New BindingSource
Dim edit As Boolean
'Dim cnn As OleDbConnection
Dim cnn As New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
Private Sub BOM_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'HemDatabase1DataSet3.partno' table. You can move, or remove it, as needed.
'Me.PartnoTableAdapter.Fill(Me.HemDatabase1DataSet3.partno)
dgv1.DataSource = Me.HemDatabase1DataSet3.partno
bs.DataSource = ds.Tables(0)
Private Sub FillByToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillByToolStripButton.Click
ds.Tables.Clear()
If TypeToolStripTextBox.Text <> "" Then
Dim sql As String = "SELECT * from (partno) WHERE type='" & TypeToolStripTextBox.Text & "';"
Dim cmd As New OleDbCommand(sql, cnn)
da = New OleDbDataAdapter(cmd)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
dgv1.DataSource = bs
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ds.Tables.Clear()
Dim sql As String = "SELECT * From partno;"
Dim cmd As New OleDbCommand(sql, cnn)
da.SelectCommand = cmd
Dim cmdbuilder As New OleDbCommandBuilder(da)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
dgv1.DataSource = bs
End Sub
Private Sub Btn_Transfer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Transfer.Click
dgv3.Rows.Clear()
For Each _rw As DataGridViewRow In dgv1.Rows
If _rw.Cells(0).Value = True Then
dgv3.Rows.Add(_rw.Cells(0).Value, _rw.Cells(1).Value, _rw.Cells(2).Value, _rw.Cells(3).Value, _rw.Cells(4).Value, _rw.Cells(5).Value, _rw.Cells(6).Value, _rw.Cells(7).Value)
End If
Next
End Sub
Button1 : Load all data in datagridview
Btn_Transfer : Display selected rows from dgv1 in dgv3
For insertion, i used this code, lately .. But i m not being able to get any response on the click event.. I mean, nothing happens !!
Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
Dim oda As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter("select * from partno", "Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
Dim ds As System.Data.DataSet = New System.Data.DataSet()
oda.Fill(ds)
'insert
Dim dr As System.Data.DataRow = ds.Tables(0).NewRow()
dr(0) = 10
oda.Update(ds)
End Sub