Updating Oracle table using Dataset (vb.net) .Help me Plssssssss.
Hi,
I'm new to VB.Net. Based on the knowledge from books and sites I tried the
below code to update an Oracle table from a windows forms application in
VB.Net. When issuing the update command I get the following error:
"Dynamic SQL generation for the UpdateCommand is not supported against a
SelectCommand that does not return any key column information."
I have defined a primary key (partycode) in my table party and in the serverexplorer
I can see that. But I don't know why the primary key is not coming into the
dataset eventhough I use "daFfsParty.FillSchema(dsFfsParty,
SchemaType.Source, "Party")". I'm defining a primary key in the code below
is because I'm getting an error when I use find() method. I've no idea why
the primary key is not getting reflected here.
when I checked the selectcommand property it is showing
"Select * from party"
I tried debuggin using the following code. and as soon as it comes to the
GetUpdateCommand it gives me the same error.
daFfsParty.UpdateCommand = objCommandBuilder.GetUpdateCommand
daFfsParty.InsertCommand = objCommandBuilder.GetInsertCommand
daFfsParty.DeleteCommand = objCommandBuilder.GetDeleteCommand
sel = daFfsParty.SelectCommand.CommandText
upd = daFfsParty.UpdateCommand.CommandText
ins = daFfsParty.InsertCommand.CommandText
del = daFfsParty.DeleteCommand.CommandText
Can anyone help me out.
My full code looks like below :
Imports System.Data
Imports System.Data.OleDb
Public Class frmParty
Inherits System.Windows.Forms.Form
Friend WithEvents bmb As BindingManagerBase
Dim dsFfsParty As New DataSet()
Dim cnFfs As New OleDbConnection("Provider=MSDAORA.1;Password=ffs;User
ID=ffs;Data Source=www")
Dim daFfsParty As New OleDbDataAdapter("SELECT * FROM party", cnFfs)
Private Sub frmParty_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
CreateDataSet()
InitializeBinding()
End Sub
Sub CreateDataSet()
Try
cnFfs.Open()
daFfsParty.FillSchema(dsFfsParty, SchemaType.Source, "Party")
daFfsParty.Fill(Me.dsFfsParty, "party")
Catch ffsFillException As System.Exception
Throw ffsFillException
Finally
cnFfs.Close()
End Try
End Sub
Sub InitializeBinding()
'**** Binding code goes here
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnSave.Click
'*** Updating the Datasource with the help of a DataSet
Dim tblParty As DataTable
tblParty = dsFfsParty.Tables("Party")
With tblParty
.PrimaryKey = New DataColumn() _
{.Columns("partycode")}
End With
Dim drCurrent As DataRow
drCurrent = dsFfsParty.Tables("Party").Rows.Find(TxtCode.Text)
'drCurrent = tblParty.Rows.Find(TxtCode.Text)
drCurrent.BeginEdit()
drCurrent("Phone") = txtPhone.Text
drCurrent.EndEdit()
Dim objCommandBuilder As New OleDbCommandBuilder(daFfsParty)
Try
daFfsParty.Update(dsFfsParty, "Party")
Catch effsupdate As System.Exception
Throw effsupdate
End Try
End Sub
End Class