Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update Sql Table Using VB
Message
From
26/12/2002 19:25:23
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Update Sql Table Using VB
Miscellaneous
Thread ID:
00735969
Message ID:
00735969
Views:
44
Hi,

I' am trying to update a table using a 2nd SQLDataAdpater which is defined in code, for each row in a different dataset filled from SqlDataAdapter1 which is created using the SqlDataAdapter Wizard.
-
-
-
' NhdTransaction Update Command String
Dim strNhdTransUpdateCommand As String
strNhdTransUpdateCommand = "UPDATE dbo.NhdTransaction " & _
"SET dbo.NhdTransaction.NhdOrderSent = 1, " & _
"dbo.NhdTransaction.NhdOrderDate = GETDATE()" & _
"WHERE dbo.NhdTransaction.FileNum=@FileNum"
-
-
-
-
NhdCreateReportOrders_Ds.WriteXml("F:\OfficeManager\NhdXml\NhdDailyOrders.XML")
' Send Nhd Report Order Email
SendNhdEmail()
' Update NhdTransaction Table for Orders Sent
Dim myNhdUpdateCommand As New _
SqlCommand(strNhdTransUpdateCommand, SqlConnection1)
myNhdUpdateCommand.CommandType = CommandType.Text
Dim DaUpdateNhdTrans As New SqlDataAdapter()
DaUpdateNhdTrans.UpdateCommand = myNhdUpdateCommand
myNhdUpdateCommand.Parameters.Add("@FileNum", SqlDbType.Int)
SqlConnection1.Open()
For Each myDataRow In NhdCreateReportOrders_Ds.Tables("NhdDailyOrders").Rows
'Intialize File Number Parameter
myNhdUpdateCommand.Parameters("@FileNum").Value = CInt(myDataRow("FileNum"))
myNhdUpdateCommand.ExecuteNonQuery()
Next
' Execute Close Connection1
SqlConnection1.Close()

I get the following error.

************** Exception Text **************
System.ArgumentException: Column 'FileNum' does not belong to table NhdDailyOrders.
at System.Data.DataRow.get_Item(String columnName)
at NhdCreateReportOrders.NhdCreateReportOrders.Form1_Load(Object sender, EventArgs e) in C:\NhdCreateReportOrders\NhdCreateReportOrders.vb:line 170
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)

How do I connect the update command with the sqldatadapter2 that I declared in code? It seems to be connected to the SqlDataAdapter1 and Dataset instead of the one I coded.

Please show me in my code how to fix this problem.

Thanks
Roland
Next
Reply
Map
View

Click here to load this message in the networking platform