ADO Novice

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

sSQL = "Select * from SeqGen where SG_NumType = '" & which & "'
oSGRs = New SqlDataAdapter(sSQL, oConn
oSGRs.MissingSchemaAction = MissingSchemaAction.AddWithKe
RecCnt = oSGRs.Fill(oDataSet, "SeqGen"

If RecCnt = 0 The
myRow = oDataSet.Tables("SeqGen").NewRow(
myRow("SG_NumType") = UCase(which
myRow("SG_CurrentValue") =
oDataSet.Tables("SeqGen").Rows.Add(myRow
oSGRs.Update(oDataSet, "SeqGen"

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Update requires a valid InsertCommand when passed DataRow collection with new rows

Source Error:

Line 85: myRow("SG_CurrentValue") =
Line 86: oDataSet.Tables("SeqGen").Rows.Add(myRow
Line 87: oSGRs.Update(oDataSet, "SeqGen"


Question: Can't I update a table the old way like I did in ADO? Help

Thanks, Don
 
Hi Don,

You need to implement Insert, Update and Delete command besides the select
one.
You might read a bit about ado.net in the .net help files...

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Don said:
sSQL = "Select * from SeqGen where SG_NumType = '" & which & "'"
oSGRs = New SqlDataAdapter(sSQL, oConn)
oSGRs.MissingSchemaAction = MissingSchemaAction.AddWithKey
RecCnt = oSGRs.Fill(oDataSet, "SeqGen")

If RecCnt = 0 Then
myRow = oDataSet.Tables("SeqGen").NewRow()
myRow("SG_NumType") = UCase(which)
myRow("SG_CurrentValue") = 1
oDataSet.Tables("SeqGen").Rows.Add(myRow)
oSGRs.Update(oDataSet, "SeqGen")

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Update requires a
valid InsertCommand when passed DataRow collection with new rows.
 
Hi Don,

In the sense that you don't have cursors you are correct (the reader is the
only exception).
However, read
Updating the Database with a DataAdapter and the DataSet
..net help topic or maybe a book on the topic (you'll find in this newsgroup
many recommendations)

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Don said:
So are you saying I can't update the old way, I can only do INSERT or UPDATE?

I have read the docs until I am blue in the face. ADO.NET is so different
from ADO. Its a natural tendency to try to apply new stuff to the old way
to get some context, but that doesn't work in this case.
 
Back
Top