I have two update sql statements for two SqlCommand object to update one DataTable with DataSet object to One Source Table. When I click on update button that's update only the first one and the second SqlCommand Object doesn't work. What's it? DataTable didn't support two Command object at one time? I write as follow:
Dim conxMain As New SqlConnection("Data Source=SERVER;Initial Catalog=DBTest;Persist Security Info=True;User ID=usr;Password=pwd")
Dim dadStockInfo As New SqlDataAdapter
Dim dsStockInfo As New DataSet
Dim transStockInfo As SqlTransaction = Nothing
Try
conxMain.Open()
transStockInfo = conxMain.BeginTransaction()
dadStockInfo.SelectCommand = New SqlCommand("SELECT * FROM Stock", conxMain, transStockInfo)
Dim builder As SqlCommandBuilder = New SqlCommandBuilder(dadStockInfo)
dadStockInfo.FillSchema(dsStockInfo, SchemaType.Source, "Stock")
dadPurchaseInfo.Fill(dsPurchaseInfo, "Stock")
Dim cmdStockUpdateCmd As SqlCommand = Nothing
cmdStockUpdateCmd = New SqlCommand("UPDATE Stock SET StockCode= 'TestCode' WHERE StockID = 4", conxMain, transStockInfo)
dsStockInfo.Tables("Stock").Columns("StockID").ReadOnly = False
dadStockInfo.UpdateCommand = cmdStockUpdateCmd
//dadStockInfo.Update(dsStockInfo, "Stock") [I have already tried this but did not work]
Dim cmdStockUpdateCmd1 As SqlCommand = Nothing
cmdStockUpdateCmd1 = New SqlCommand("UPDATE Stock SET StockCode= 'Test-Code2' WHERE StockID = 1", conxMain, transPurchaseInfo)
dadStockInfo.UpdateCommand = cmdStockUpdateCmd1
dadStockInfo.Update(dsStockInfo, "Stock")
transStockInfo.Commit()
Can't I use like above? please point me out !
Hello ! Help me! F1 :)