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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Adapter update command

Status
Not open for further replies.

simsima

Technical User
Jan 16, 2003
9
GB
I am trying to create oledb data adapter update command

I have created the select command successfully, data gets filled to the data grid but i make some change to the data and want to write back the changes howeover it won't work because may update command might not be correct any help will be welcomed

Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.Common

Public Class Form1
Friend WithEvents cmdSelectionpat As New OleDbCommand()
Friend WithEvents cmdInsertpat As New OleDbCommand()
Friend WithEvents cmdUpdatepat As New OleDbCommand()
Friend WithEvents cmdDeletepat As New OleDbCommand()

Dim dspat As New DataSet()
Dim dbconn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Password=;User ID=Admin;Data Source='C:\ant_tp_stats.mdb'")
Friend WithEvents dapat As New OleDbDataAdapter()
Dim parameter As OleDbParameter

public Sub New()

' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

dapat.SelectCommand = cmdSelectionpat
dapat.InsertCommand = cmdInsertpat
dapat.UpdateCommand = cmdUpdatepat
dapat.DeleteCommand = cmdDeletepat

'the select command
cmdSelectionpat.CommandText = "select patno,pfirstname,psurname from tb_patient"

' the update command
cmdUpdatepat.CommandText = "UPDATE tb_patient SET PatNo = ?, pFirstName = ?, pSurname = ?" _
& "WHERE (PatNo = ?)"
cmdUpdatepat.Parameters.Add("patno", OleDbType.BigInt, 8, "patno")
cmdUpdatepat.Parameters.Add("pfirstname", OleDbType.VarChar, 8, "pfirstname")
cmdUpdatepat.Parameters.Add("psurname", OleDbType.VarChar, 8, "psurname")

cmdSelectionpat.Connection = dbconn
cmdUpdatepat.Connection = dbconn
end sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'update button

dapat.Update(dspat)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'button to fill the data grid with the selection

Me.dbconn.Open()
dspat.Clear()
dapat.Fill(dspat)
Me.Dgvpatients.DataSource = dspat.Tables(0)
Me.OleDbConn.Close()
End Sub


end class

I get an error Saying no value given one or more parameters
 
This forum is for VB 5 & 6. You appear to be using vb.net, as such I suggest you re-post your question in that forum forum796

You're likely to get better advice, in a more timely manner if you post your question in the appropriate forum.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top