0

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

Edited by PM312

2
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by PM312
0

Try this

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

giving below error

The DataAdapter.SelectCommand property needs to be initialized.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.