Hi,
I need to code a function add rows to a dataset from a text file. I have not used the DataRow before and I am running into problems. I get the message "use the keyword new to create an object instance" when the statement, dsNewRow = dset.Tables("Table1").NewRow() is executed. When I add the new to Dim dsNewRow as New DataRow I get the message ,..is not accessible in sthe contextbecause it is protected".
I am at a lost as how to correct the code. Also, I do not know if the remaing code will work.
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\TestMyCode.mdb;User Id=admin;Password=;")
Dim da As OleDb.OleDbDataAdapter
Dim dset As New DataSet
Dim dsNewRow As DataRow
Dim Sql As String
con.Open()
Sql = "SELECT * FROM Table1"
da = New OleDb.OleDbDataAdapter(Sql, con)
dset.DataSetName = "TestDataAccessMethods.mdb"
dsNewRow = dset.Tables("Table1").NewRow()
For i As Integer = 0 To 22000
dsNewRow.Item("fld1") = "hello everyone"
dsNewRow.Item("fld2") = "test it"
dset.Tables("Table1").Rows.Add(dsNewRow)
da.Update(dset, "Table1")
Next
con.Close()
con.Dispose()
I need to code a function add rows to a dataset from a text file. I have not used the DataRow before and I am running into problems. I get the message "use the keyword new to create an object instance" when the statement, dsNewRow = dset.Tables("Table1").NewRow() is executed. When I add the new to Dim dsNewRow as New DataRow I get the message ,..is not accessible in sthe contextbecause it is protected".
I am at a lost as how to correct the code. Also, I do not know if the remaing code will work.
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\TestMyCode.mdb;User Id=admin;Password=;")
Dim da As OleDb.OleDbDataAdapter
Dim dset As New DataSet
Dim dsNewRow As DataRow
Dim Sql As String
con.Open()
Sql = "SELECT * FROM Table1"
da = New OleDb.OleDbDataAdapter(Sql, con)
dset.DataSetName = "TestDataAccessMethods.mdb"
dsNewRow = dset.Tables("Table1").NewRow()
For i As Integer = 0 To 22000
dsNewRow.Item("fld1") = "hello everyone"
dsNewRow.Item("fld2") = "test it"
dset.Tables("Table1").Rows.Add(dsNewRow)
da.Update(dset, "Table1")
Next
con.Close()
con.Dispose()