I have a table tbl_Users with UserID as primary key.
Update code like this:
Dim strSQL As String
Dim intCnt As Integer
Dim con As OleDbConnection
Dim oDTAdapter As OleDbDataAdapter
Dim drRow As DataRow
Dim dtUsers As New DataTable()
Try
con = New OleDbConnection
("Provider=MSDAORA.1;Password=*;User ID=*;Data
Source=*;Persist Security Info=True")
strSQL = "SELECT * FROM tbl_Users"
con.Open()
Try
oDTAdapter = New OleDbDataAdapter(strSQL,
con)
oDTAdapter.Fill(dtUsers)
intCnt = dtUsers.Rows.Count
Dim oCB As OleDbCommandBuilder = New
OleDbCommandBuilder(oDTAdapter)
'--Create primary key
Dim pk(0) As DataColumn
pk(0) = dtUsers.Columns("UserID")
dtUsers.PrimaryKey = pk
drRow = dtUsers.Rows(0)
drRow("usrReserved") = DBNull.Value
oDTAdapter.Update(dtUsers)
Finally
con.Close()
End Try
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try
There will be exception created in Update line:
Dynamic SQL generation for the UpdateCommand is not
supported against a SelectCommand that does not return any
key column information.
Now do this: just change table name from tbl_Users to
tbl_Usrs, there will be no exceptions at all!
There are also other strange things going on with ADO.Net
to Oracle. ADO.Net doesn't like oracle data type like
number(18,6) when the number is very small (like .00006).
|