Every time i try to run this codei get the following error:
"'System.Data.DataRow.Protected Friend Sub New(builder As System.Data.DataRowBuilder)' is not accessible in this context because it is 'Protected Friend'.
"
this is my first time to insert using oledb and the With method.

Imports System.Data.OleDb
Public Class frmAddd
    Dim daReservation As New OleDbDataAdapter()
    Dim dsReservation As New DataSet()
''
''
Dim con As OleDbConnection
        Dim SqlString As String = "INSERT INTO 12Testing (Name, Surname)  VALUES ('" & Me.txtName.Text & "', '" & Me.txtSurname.Text & "')"
        Dim data_base As String = " Data Source=;Initial Catalog=Testing_DB;User ID=;Password="
        'con = New OleDbConnection(data_base)
        'Dim conn As OleDbCommand = con.CreateCommand()
        'con.Open()
        'Dim cmnd As OleDbCommand = New OleDbCommand(SqlString, con)
        'cmnd.ExecuteNonQuery()        ' Execute the command here
        'con.Close()

        Dim dt As DataTable = dsReservation.Tables("12Testing")
        Dim newRow As New DataRow
        dt.Rows.Add(newRow)
        With dt
            .Rows(0)("Name") = txtName.Text
            .Rows(0)("Surname") = txtSurname.Text

            daReservation.Update(dsReservation, "12Testing")
        End With

try

with newrow
.Columns.Add("Name", System.Type.GetType("System.String"))
.Columns.Add("Surname", System.Type.GetType("System.String"))
end with

newRow("Name")=txtname.text
newRow("Surname")=txtsurname.text

'Add row to datatable
   dt.Rows.Add(newRow)

I haven't test it but it should work

when i try and run the new code i get the following new errors:Columns' is not a member of 'System.Data.DataRow'. and 'System.Data.DataRow.Protected Friend Sub New(builder As System.Data.DataRowBuilder)' is not accessible in this context because it is 'Protected Friend'.

Dim con As OleDbConnection
        Dim SqlString As String = "INSERT INTO 12Testing (Name, Surname)  VALUES ('" & Me.txtName.Text & "', '" & Me.txtSurname.Text & "')"
        Dim data_base As String = " Data Source=;Initial Catalog=Testing_DB;User ID=;Password="

        Dim dt As DataTable = dsReservation.Tables("12Testing")
        Dim newRow As New DataRow
        dt.Rows.Add(newRow)
        With newRow
            .Columns.Add("Name", System.Type.GetType("System.String"))
            .Columns.Add("Surname", System.Type.GetType("System.String"))
        End With

        newRow("Name") = txtName.Text
        newRow("Surname") = txtSurname.Text
       
        daReservation.Update(dsReservation, "12Testing")

that is because you add the row before adding the columns
As you can see in my example i first add the columns and then the row

in other words move
dt.Rows.Add(newRow)
under the with statement

still get the same errors

then i don't know! the only thing im doing different is that i dont use the dataadapter

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.