Solved

Simple Q: simple SQL update code?

Posted on 2003-12-04
6
346 Views
Last Modified: 2010-04-16
Hi all...
it's a shame I have to ask, but what is the easiest way to do an update on a Access file?

currently I have:
----------------------
string connectionCC = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ Server.MapPath("/data/network.mdb");
string SQLquery = "UPDATE....."
OleDbConnection myConn = new OleDbConnection(lrFuncs.connectionCC);



----------------------
How can I "execute" this query?
0
Comment
Question by:Smoerble
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:astankovic
ID: 9875411
string connectionCC = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ Server.MapPath("/data/network.mdb");
string SQLquery = "UPDATE....."
OleDbConnection myConn = new OleDbConnection(lrFuncs.connectionCC);OleDbCommand cmd = New SqlClient.SqlCommand(SQLquery, connectionCC);

connectionCC.Open();
cmd.ExecuteNonQuery(); // this does the update
connectionCC.Close();

You should probably also wrap this in try/catch block too.

Hope this helps,
Alex
0
 
LVL 4

Accepted Solution

by:
astankovic earned 125 total points
ID: 9875426
Sorry, the I missed the line break, in previous post.
This is how is should look:

OleDbConnection myConn = new OleDbConnection(lrFuncs.connectionCC);
OleDbCommand cmd = New SqlClient.SqlCommand(SQLquery, connectionCC);
0
 
LVL 4

Expert Comment

by:astankovic
ID: 9875448
Ok, I don't know what's wrong with me... probably to much cut and paste...

Here is the correct one:
string connectionCC = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ Server.MapPath("/data/network.mdb");
string SQLquery = "UPDATE....."
OleDbConnection myConn = new OleDbConnection(lrFuncs.connectionCC);
OleDbCommand cmd = new OleDbCommand(SQLquery, connectionCC);

connectionCC.Open();
cmd.ExecuteNonQuery(); // this does the update
connectionCC.Close();

You should probably also wrap this in try/catch block too.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:Smoerble
ID: 9875469
the line:
---------
OleDbCommand cmd = New SqlClient.SqlCommand(SQLquery, connectionCC);
---------
does not work, SqlClient gets red marks and the debugger says: ";" expected.
Any idea?
0
 

Author Comment

by:Smoerble
ID: 9875522
Hehe, we posted at the same time ;)
Anyways, still some probs with your code:

OleDbCommand cmd = new OleDbCommand(SQLquery, connectionCC);
needs to be
OleDbCommand cmd = new OleDbCommand(SQLquery, myConn);

but now it works, so thank you ;)
0
 

Author Comment

by:Smoerble
ID: 9875528
Ups, accepted the wron answer, but you still gave the answer I needed, so I leave it like it is, thank again ;)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question