|
 |
aspx_beginners thread: SQL Update Using ASP.NET and Access 2000
Message #1 by steveproctor@c... on Sat, 15 Jun 2002 13:31:41
|
|
Can anyone refer me to an online source that explains (with both code
samples and hopefully a narrative explanation) how to update a database in
ASP.NET? The database is Access 2000. Right now, I'm trying to figure
how to update an existing record, not add a new one.
As background, I've had great difficulty in updating a database using
ASP.NET. I've used code samples from two different SAMS books - ASP.NET
Unleashed and Teach Yourself ASP.NET in 21 days. (The 21 day book is
really bad and not recommended.) Nothing is working. (I'm looking
forward to Wrox's new release on using databases in ASP.NET). I've posted
code snippets before and gotten some assistance,which I've appreciated.
But I'm still not understanding the problem.
Any help is appreciated.
Steve
Message #2 by David Barnes <DavidB@w...> on Sat, 15 Jun 2002 13:40:23 +0100
|
|
Hi Steve
I don't know of any online sources for this. Hopefully this simple example
will help. If you're using VB.NET then the code you need will be something
like this:
' set up connection
Dim myConnection As OleDbConnection = New _
OleDbConnection(--WHATEVER CONNECTION STRING YOU
USE--)
' set up command object with a connection and an SQL statement
Dim myCommand As OleDbCommand = New OleDbCommand()
myCommand.Connection = myConnection
myCommand.CommandText = "UPDATE authors SET au_lname=@au_lname,
au_fname=@au_fname WHERE au_id=@au_id"
' set values of the parameters
myCommand.Parameters.Add("@au_id", WHATEVER-VARIABLE-CONTAINS-THE-ID)
myCommand.Parameters.Add("@au_lname",
WHATEVER-VARIABLE-CONTAINS-THE-LASTNAME)
myCommand.Parameters.Add("@au_fname",
WHATEVER-VARIABLE-CONTAINS-THE-FIRSTNAME)
' open the connection, run the query, close the connection
myConnection.Open()
Dim rowsAffected As Integer = myCommand.ExecuteNonQuery()
myConnection.Close()
Then check the value of rows affected if you wish.
Hopefully the SQL here is pretty self explanatory: UPDATE tablename SET
columname=parameter, columnname2=parameter2, ...... WHERE
criteria=criteria_parameter
The WHERE part can contain anything that the WHERE clause in a SELECT
statement could contain. Parameters always begin with @
I hope this helps. I've deliberately kept this brief because I'm
horrifically busy, and don't want to elaborate more than needed. But if it's
not clear, please let me know...
David
Editor, Wrox Press
> -----Original Message-----
> From: steveproctor@c... [mailto:steveproctor@c...]
> Sent: 15 June 2002 14:32
> To: aspx_beginners
> Subject: [aspx_beginners] SQL Update Using ASP.NET and Access 2000
>
>
> Can anyone refer me to an online source that explains (with both code
> samples and hopefully a narrative explanation) how to update
> a database in
> ASP.NET? The database is Access 2000. Right now, I'm trying
> to figure
> how to update an existing record, not add a new one.
>
> As background, I've had great difficulty in updating a database using
> ASP.NET. I've used code samples from two different SAMS
> books - ASP.NET
> Unleashed and Teach Yourself ASP.NET in 21 days. (The 21 day book is
> really bad and not recommended.) Nothing is working. (I'm looking
> forward to Wrox's new release on using databases in ASP.NET).
> I've posted
> code snippets before and gotten some assistance,which I've
> appreciated.
> But I'm still not understanding the problem.
>
> Any help is appreciated.
>
> Steve
>
|
|
 |