aydinozdemir
Member
- Joined
- May 15, 2011
- Messages
- 15
- Programming Experience
- Beginner
hello. i have got a form with 2 buttons and a tabcontrol.
button1 adds tabpages and datagridviews as the number of data tables inside of my database file, then fills the grids. works good
button2 saves the dataset back to database. this doesnt work.i tried
da.Update(ds2, "name_surname")
da.Update(ds2.Tables(0))... etc and still no success. where i am doing wrong? can you help me please?
Imports System.Data.OleDb
PublicClass Form4
Dim con AsNew OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Ders\lessons.mdb")
Dim cmd As OleDbCommand
Dim cb As OleDbCommandBuilder
Dim da As OleDbDataAdapter
Dim ds AsNew DataSet
Dim ds2 AsNew DataSet
Dim sql AsString
Dim dt As DataTable
Dim DGV AsNew DataGridView
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TabControl1.Controls.Clear()
Try
con.Open()
dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, NewObject() {Nothing, Nothing, Nothing, Nothing})
Dim int AsInteger
Dim i AsInteger
i = -1
For int = 0 To dt.Rows.Count - 1
If dt.Rows(int)!TABLE_TYPE.ToString = "TABLE"Then
Dim teacher AsString
teacher = dt.Rows(int)!TABLE_NAME
If teacher <> "student"Then
Try
i = i + 1
sql = "Select * from " & teacher & ""
da = New OleDbDataAdapter(sql, con)
da.Fill(ds, "" & teacher & "")
ds2.Merge(ds)
ds.Clear()
Dim NTP AsNew TabPage
Dim LineOfText AsString
Dim i2 AsInteger
Dim aryTextFile() AsString
LineOfText = teacher
aryTextFile = LineOfText.Split("_")
For i2 = 0 To UBound(aryTextFile)
LineOfText = String.Join(" ", aryTextFile)
Next i2
TabControl1.Controls.Add(NTP)
NTP.Text = (LineOfText)
DGV = New DataGridView
NTP.Controls.Add(DGV)
DGV.Name = i
DGV.DataSource = ds2.Tables(i)
'DGV.DataMember = "" & teacher & ""
DGV.Size = New System.Drawing.Size(927, 594)
con.Close()
Catch ex As Exception
MsgBox(ex.ToString)
EndTry
EndIf
EndIf
Next
i = i + 1
MsgBox(i.ToString + " Listed.")
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Data Load Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
EndTry
con.Close()
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
cb = New OleDbCommandBuilder(da)
da.Update(ds2)
ds2.AcceptChanges()
Catch ex As Exception
MsgBox(ex.ToString)
EndTry
EndSub
EndClass
button1 adds tabpages and datagridviews as the number of data tables inside of my database file, then fills the grids. works good
button2 saves the dataset back to database. this doesnt work.i tried
da.Update(ds2, "name_surname")
da.Update(ds2.Tables(0))... etc and still no success. where i am doing wrong? can you help me please?
Imports System.Data.OleDb
PublicClass Form4
Dim con AsNew OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Ders\lessons.mdb")
Dim cmd As OleDbCommand
Dim cb As OleDbCommandBuilder
Dim da As OleDbDataAdapter
Dim ds AsNew DataSet
Dim ds2 AsNew DataSet
Dim sql AsString
Dim dt As DataTable
Dim DGV AsNew DataGridView
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TabControl1.Controls.Clear()
Try
con.Open()
dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, NewObject() {Nothing, Nothing, Nothing, Nothing})
Dim int AsInteger
Dim i AsInteger
i = -1
For int = 0 To dt.Rows.Count - 1
If dt.Rows(int)!TABLE_TYPE.ToString = "TABLE"Then
Dim teacher AsString
teacher = dt.Rows(int)!TABLE_NAME
If teacher <> "student"Then
Try
i = i + 1
sql = "Select * from " & teacher & ""
da = New OleDbDataAdapter(sql, con)
da.Fill(ds, "" & teacher & "")
ds2.Merge(ds)
ds.Clear()
Dim NTP AsNew TabPage
Dim LineOfText AsString
Dim i2 AsInteger
Dim aryTextFile() AsString
LineOfText = teacher
aryTextFile = LineOfText.Split("_")
For i2 = 0 To UBound(aryTextFile)
LineOfText = String.Join(" ", aryTextFile)
Next i2
TabControl1.Controls.Add(NTP)
NTP.Text = (LineOfText)
DGV = New DataGridView
NTP.Controls.Add(DGV)
DGV.Name = i
DGV.DataSource = ds2.Tables(i)
'DGV.DataMember = "" & teacher & ""
DGV.Size = New System.Drawing.Size(927, 594)
con.Close()
Catch ex As Exception
MsgBox(ex.ToString)
EndTry
EndIf
EndIf
Next
i = i + 1
MsgBox(i.ToString + " Listed.")
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Data Load Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
EndTry
con.Close()
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
cb = New OleDbCommandBuilder(da)
da.Update(ds2)
ds2.AcceptChanges()
Catch ex As Exception
MsgBox(ex.ToString)
EndTry
EndSub
EndClass
Last edited: