I am getting below Error
“Update requires a valid InsertCommand when passed DataRow collection with new rows.”

Below is the code in Module
Module ModDBConnection

Public CnCommon As New SqlConnection

Public DTCodeMaster As New DataTable
Public DACodeMaster As New SqlDataAdapter
Public CBCodeMaster As New SqlCommandBuilder

Public Sub CommonCn()
CnCommon = New SqlConnection
CnCommon.ConnectionString = "Data Source=DELTA\SQL_PRAVIN;Initial CatAlog=PAYDATANET;User ID=accounts;Password=accounts"
CnCommon.Open()
End Sub

Public Sub RSCodeMaster()
Call CommonCn()
Dim Sas As String = "SELECT * FROM Tbl_AccountMaster "
Dim DACodeMaster = New SqlClient.SqlDataAdapter(Sas, CnCommon)
Dim CBCodeMaster = New SqlClient.SqlCommandBuilder(DACodeMaster)
DACodeMaster.Fill(DTCodeMaster)
End Sub

End Module

Below code is on my form

Call RSCodeMaster()
Dim RowNo As Integer
Dim adnewrow As DataRow = DTCodeMaster.NewRow()
DTCodeMaster.Rows.Add(adnewrow)
RowNo = DTCodeMaster.Rows.Count - 1
adnewrow("Acct_Code") = TxtAcctCode.Text
DACodeMaster.Update(DTCodeMaster) ' Errow on this line

What could be the issue?
Thanks

Recommended Answers

All 3 Replies

Try this

adnewrow("Acct_Code") = TxtAcctCode.Text
DACodeMaster.UpdateCommand = CBCodeMaster.GetUpdateCommand()
DACodeMaster.Update(DTCodeMaster)

giving below error

The DataAdapter.SelectCommand property needs to be initialized.

If i put the code from module to form its works. but i want the code in module because i will need this connection code several time in my project.

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.