Hi all, I am able to save, update, delete etc to data in already existing tables, but i can't seem to work out how to create and save a new table to a database. Using Visual Studio 2005, VB.
I've tried this and few other ways of coding it, but i can't seem to get it right:
_______________ _______________ _______________ _________
Public Class Form1
Dim con As New OleDb.OleDbConn ection
Dim ds As New DataSet
Dim dt As New DataTable
Dim da As New OleDb.OleDbData Adapter
Dim dr As New DataRowAction
Dim dc As New DataColumn
Dim sql As String
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
dt.TableName = "NewTableTe st1"
dt.Columns.Add( dc)
dt.Rows.Add(dr)
ds.Tables.Add(d t)
da.Update(ds)
End Sub
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
con.ConnectionS tring = "PROVIDER=Micro soft.Jet.OLEDB. 4.0;Data Source = C:\Users\Andrew \AFL2008Schedul eNEW.mdb"
con.Open()
sql = "SELECT * FROM AndrewsPicks"
da = New OleDb.OleDbData Adapter(sql, con)
da.Fill(ds, "AFL2008Schedul eNEW")
End Sub
End Class
_______________ _______________ _______________ _______
Error for this code = InvalidOperatio nException, refering to the code "da.Update( ds)"
Can't seem to find examples of what im looking for anywhere, any help would be appreciated.
cheers,
-Andrew
I've tried this and few other ways of coding it, but i can't seem to get it right:
_______________ _______________ _______________ _________
Public Class Form1
Dim con As New OleDb.OleDbConn ection
Dim ds As New DataSet
Dim dt As New DataTable
Dim da As New OleDb.OleDbData Adapter
Dim dr As New DataRowAction
Dim dc As New DataColumn
Dim sql As String
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
dt.TableName = "NewTableTe st1"
dt.Columns.Add( dc)
dt.Rows.Add(dr)
ds.Tables.Add(d t)
da.Update(ds)
End Sub
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
con.ConnectionS tring = "PROVIDER=Micro soft.Jet.OLEDB. 4.0;Data Source = C:\Users\Andrew \AFL2008Schedul eNEW.mdb"
con.Open()
sql = "SELECT * FROM AndrewsPicks"
da = New OleDb.OleDbData Adapter(sql, con)
da.Fill(ds, "AFL2008Schedul eNEW")
End Sub
End Class
_______________ _______________ _______________ _______
Error for this code = InvalidOperatio nException, refering to the code "da.Update( ds)"
Can't seem to find examples of what im looking for anywhere, any help would be appreciated.
cheers,
-Andrew
Comment