Re: How to do a simple update command with ado.net?
- From: Paul Clement <UseAdddressAtEndofMessage@xxxxxxxxxxxxxx>
- Date: Tue, 02 Aug 2005 10:11:44 -0500
On 1 Aug 2005 09:58:01 -0700, "Sean" <nbSean@xxxxxxxxx> wrote:
¤ I am trying to execute a simple SQL Update command on an Access
¤ database. I have an OleDBConnection (gDatabaseConn) that has
¤ successfully been executing select commands, but I cannot get an update
¤ command to work. Here is the code in question:
¤
¤ Dim cmdUpdate As New OleDb.OleDbCommand("", gDatabaseConn)
¤
¤ sSQL = "UPDATE NoteTable SET AcctID = '" & Account.sAcctID
¤ sSQL = sSQL & "' WHERE AcctNo = '" & Account.sAccountNo & "'"
¤
¤ cmdUpdate.CommandText = sSQL
¤ cmdUpdate.ExecuteNonQuery()
¤
¤ The call to ExecuteNonQuery throws an exception with the message "No
¤ value given for one or more required parameters". Both of the
¤ variables used in the string have values. Is ADO.NET capable of
¤ running a simple SQL command like this, or do I need to investigate
¤ OleDBParameter objects? This way would be preferrable, since I am not
¤ using DataTables or DataRows.
See if the following example helps:
Dim ConnectionString As String
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=<database path goes here>"
Dim gDatabaseConn As New System.Data.OleDb.OleDbConnection(ConnectionString)
gDatabaseConn.Open()
Dim cmdUpdate = New System.Data.OleDb.OleDbCommand("UPDATE NoteTable SET AcctID = ? WHERE
AcctNo = ?", gDatabaseConn)
Dim QueryParameter As New OleDbParameter("@Param1", OleDbType.VarChar)
QueryParameter.Value = Account.sAcctID
cmdUpdate.Parameters.Add(QueryParameter)
QueryParameter = New OleDbParameter("@Param2", OleDbType.VarChar)
QueryParameter.Value = Account.sAccountNo
cmdUpdate.Parameters.Add(QueryParameter)
cmdUpdate.CommandType = CommandType.Text
cmdUpdate.ExecuteNonQuery()
gDatabaseConn.Close()
Paul
~~~~
Microsoft MVP (Visual Basic)
.
- References:
- Prev by Date: reading text file using OLEDB into dataset
- Next by Date: Oracle 8i, OleDB driver and Batch Queries
- Previous by thread: Re: How to do a simple update command with ado.net?
- Next by thread: Store and retrieve an array of double into image field(sql server)
- Index(es):
Relevant Pages
|