Solved

Simple Q: simple SQL update code?

Posted on 2003-12-04
6
363 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 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