Solved

Simple Q: simple SQL update code?

Posted on 2003-12-04
6
326 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now