Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataTable/DataSet help

Status
Not open for further replies.

bigfoot

Programmer
Joined
May 4, 1999
Messages
1,779
Location
US
I'm reading from an ODBCConnection from an AS/400.
I can read the data ok, and the dataadapter gets the info great. But when I try to update the information back, it gives me this error:

Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

Here my code:

'AS/400 Connection
Dim myConnection = New System.Data.Odbc.OdbcConnection
'This is responsible for getting the data from the tables
Dim myDataAdapter As New System.Data.Odbc.OdbcDataAdapter
'This will be my copy of the table in memory
Dim myDataSet As DataSet = New DataSet

Dim myDataRow As DataRow

'Set the connection string
myConnection.ConnectionString = "DSN=as400;DBQ=garylib;SYSTEM=S10A1234;UID=myuser;PWD=mypassword"
'Set the Select Command properties
myDataAdapter.SelectCommand = New OdbcCommand
'Set the select command's connection to the main connection
myDataAdapter.SelectCommand.Connection = myConnection
'Set the command text of the data adapter. This is the query select
myDataAdapter.SelectCommand.CommandText = "Select OrdIdn, TrnDat, TrnTim, AscCus, PoNumb, PoDate, DelDat, DsvEnd From GARYLIB.INT850IH"
'This tells the select command that it's a query, and not a table, or stored proc.
myDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

'Open the connection
Try
myConnection.Open()
Catch errobj As Exception
MessageBox.Show(errobj.Message)
End Try

'Tried with and without this
' Set the MissingSchemaAction property to AddWithKey because Fill will not cause primary
' key & unique key information to be retrieved unless AddWithKey is specified.
myDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

myDataAdapter.FillSchema(myDataSet, SchemaType.Mapped, "INT850IH")

'Fill the DataSet object with data. We can call the second param anything
'but I am using the AS/400's table name
myDataAdapter.Fill(myDataSet, "INT850IH")

'Close the database connection
myConnection.close()

'Just to let me know it's done
Console.Write("Done")

'This did not work
'myDataRow = myDataSet.Tables("INT850IH").NewRow()
'myDataRow = myDataTable.NewRow
'myDataRow("OrdIdn") = 10
'myDataRow("TrnDat") = 30819
'myDataRow("TrnTim") = 921
'myDataRow("AscCus") = "12345"
'myDataRow("PoNumb") = "55555"
'myDataRow("PoDate") = 30815
'myDataRow("DelDat") = 30816
'myDataRow("DsvEnd") = "6666"
'myDataSet.Tables("INT850IH").Rows.Add(myDataRow)


'I even tried just changing a row....
myDataSet.Tables("INT850IH").Rows(0)("TrnDat") = "20"


Dim myDataRowsCommandBuilder As OdbcCommandBuilder = New OdbcCommandBuilder(myDataAdapter)

'HERE is where it crashes
Try
myDataAdapter.Update(myDataSet, "INT850IH")
Catch errobj As Exception
MessageBox.Show(errobj.Message)
End Try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top