Solved

Simple Q: simple SQL update code?

Posted on 2003-12-04
6
375 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

696 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