Hi i have the following code.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New OleDbConnection
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim dsnewrow As DataRow

Dim cb As New OleDbCommandBuilder(da)

Dim a As String
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\DB.mdb;Jet OLEDB:Database Password=123"
con.Open()
a = "select * from Login"
da = New OleDbDataAdapter(a, con)
da.Fill(ds, "Login1")
dsnewrow = ds.Tables("Login1").NewRow()
ds.Tables("Login1").Rows.Add(dsnewrow)
dsnewrow.Item("Lid") = "test"
dsnewrow.Item("Name") = Uname2.Text.ToString()
dsnewrow.Item("Lps") = psw1.Text.ToString()
dsnewrow.Item("Acces1") = Acs.Text.ToString()
dsnewrow.Item("Date1") = DTp1.Value.ToString()
da.Update(ds, "Login1")
Uname2.Text = ""
psw1.Text = ""
Acs.Text = ""
DTp1.Value = Today()
con.Close()

I get the following error when i try to run the code and update in the MS access database Update requires a valid InsertCommand when passed DataRow collection with new rows.

Kindly help me on this issue.

Thanks

Can u please let me know how it need to be created. As i am new to vb.net. I am trying to learn this coding. When i check up the link i am not able to understand the post. So kindly please explain me how it need to the done.

Thanks

Check Out The Highlighted Code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim dsnewrow As DataRow

con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\DB.mdb;Jet OLEDBatabase Password=123"

Dim sql As String = "select * from Login;"

Dim cmd As New OleDbCommand()

    With cmd
      .CommandType = CommandType.Text
      .Connection = con
      .CommandText = sql
    End With

da = New OleDbDataAdapter(cmd)
da.SelectCommand = cmd

Dim cb As New OleDbCommandBuilder(da)

da.Fill(ds, "Login1")


dsnewrow = ds.Tables("Login1").NewRow()
ds.Tables("Login1").Rows.Add(dsnewrow)
dsnewrow.Item("Lid") = "test"
dsnewrow.Item("Name") = Uname2.Text.ToString()
dsnewrow.Item("Lps") = psw1.Text.ToString()
dsnewrow.Item("Acces1") = Acs.Text.ToString()
dsnewrow.Item("Date1") = DTp1.Value.ToString()
da.Update(ds, "Login1")
Uname2.Text = ""
psw1.Text = ""
Acs.Text = ""
DTp1.Value = Today()

Hey Thanks for your code. I will check it up and let u know if it is working or not.

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.