Solved

Simple Q: simple SQL update code?

Posted on 2003-12-04
6
335 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Allow space in this pattern 2 46
Authentication of Web Services 3 46
C# application error "Parameter Is Not Valid". 3 75
Error on link 14 36
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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!
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
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 …

929 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

13 Experts available now in Live!

Get 1:1 Help Now