I am Rida, i have connected my access database to vb.net and program is capable to show the database in the datagridview. but what i want is when i change the data in the datagridview and click onto update button,changes i made should be saved in database so when i execute the application again i should be able to see the updated database in the datagridview.
guide me to add data as well as to delete data too
pls help me !!
here is the code..
i have three buttons on the form else then the datagridview.
button1=update
button2=add
button3=delete
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Windows.Forms.DataGridView
Public Class Form1
Dim row As Integer
Dim col As Integer
Dim currentTime As System.DateTime = System.DateTime.Now
Dim DataSet1 As New DataSet()
'Dim com As New OleDb.OleDbCommandBuilder(OleDbDataAdapter1)
Dim SQLString As String = "SELECT * FROM Table1"
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\members.accdb;User ID=admin"
Dim OleDBConn1 As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(ConnString)
Dim OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, OleDBConn1)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDBConn1.Open()
OleDbDataAdapter1.Fill(DataSet1, "Table1")
DataGridView1.DataSource = DataSet1.Tables("Table1")
TextBox1.Text = currentTime
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DataSet1.Tables("Table1").AcceptChanges()
OleDbDataAdapter1.Update(DataSet1, "table1")
Dim item As New DataGridViewRow
DataGridView1.AllowUserToAddRows = True
item.CreateCells(DataGridView1)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
OleDbDataAdapter1.AcceptChangesDuringUpdate = True
'OleDbDataAdapter1.UpdateCommand("table1")
Dim j As Integer
j = 0
DataSet1.Tables("Table1").Rows(j).Item(1) = TextBox2.Text
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim i As Integer
i = 0
DataSet1.Tables("Table1").Rows(i).Delete()
End Sub

New Topic/Question
Reply




MultiQuote





|