hallo
Iam trying to insert a row into a access database using visual c# and iam getting an error " cannot open the action query". here is my code -
-
private void button1_Click(object sender, EventArgs e)
-
{
-
txt1 = textBox1.Text;
-
txt2 = textBox2.Text;
-
String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Userinfo.accdb";
-
OleDbConnection connection = new OleDbConnection(connectionString);
-
OleDbCommand command = new OleDbCommand();
-
-
-
command.CommandType = CommandType.TableDirect;
-
command.CommandText = "INSERT INTO userinfo (Username, Pwd) VALUES (‘" + txt1 + "’ , ‘" + txt2 + "’)";
-
command.Connection = connection;
-
connection.Open();
-
command.ExecuteNonQuery(); // getting in this line .
-
connection.Close();
-
-
any idea why is this error ?
Thank you.
Dinesh.
Nov 18 '08
14 3841
I would say your problem is using the illegal quote character in your string. try using the regular ' single quote and see if that works for you.
hallo plater,
i have changed the code and the line which u say to change to single quote as follows -
OleDbCommand cmdInsert = new OleDbCommand("INSERT INTO userinfo (Username, Pwd,Openid,ServerUrl)" + "VALUES (" + txt1 + "," + txt2 + "," + txt3 + "," + txt4 + ")", cnJetDB);
-
then iam getting error in the executenonquery line.
thank you.
Dinesh.
When passing text to the database, you need to pass it surrounded by single quotes. Suppose your value is stored in a variable called text, you would pass in "'"+ text + "'". Have a look at other people's code and you will see all those quotes all over the place. Not very elegant I might add. Better use Parameters and let the drivers handle that for you.
Plater 7,872
Recognized Expert Expert
Edit: ok, so yeah, the single quotes you used were the left-single-quote and right-single-quote. You need the non-directional-single quote -
"INSERT INTO userinfo (Username, Pwd) VALUES ('" + txt1 + "' , '" + txt2 + "')";
-
OK, I think the problem is that you are trying to insert into varchar fields without using single quotes around your values.
Try this: - string cmdText = String.Format("INSERT INTO userinfo (Username, Pwd,Openid,ServerUrl) VALUES ('{0}','{1}','{2}','{3}')",txt1,txt2,txt3,txt4);
-
OleDbCommand cmdInsert = new OleDbCommand(cmdText,cnJetDB);
-
I've used the String.Format method here. Notice how much cleaner and easier it is to understand than that mess of string concatenation you had before.
OK, I think the problem is that you are trying to insert into varchar fields without using single quotes around your values.
Try this: - string cmdText = String.Format("INSERT INTO userinfo (Username, Pwd,Openid,ServerUrl) VALUES ('{0}','{1}','{2}','{3}')",txt1,txt2,txt3,txt4);
-
OleDbCommand cmdInsert = new OleDbCommand(cmdText,cnJetDB);
-
I've used the String.Format method here. Notice how much cleaner and easier it is to understand than that mess of string concatenation you had before.
Thank you so much moderator. You are right the mess i have made to the string concatenation. thank you once again. now the problem is solved.. I have one more doubt?. I have this database "userinfo.accdb " in my c:\userinfo.acc db". I have added this to my project. so when i use the executable version of my project ( i mean the exe file the bin folder) in another computer should i also carry this userinfo.accdb. if so how can change the datasource of the database in the .exe version of the project.
Dinesh.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Koen |
last post by:
Hi all,
At work I created a database which is really helpful. The database is used
by approx 15 users. Everything worked great, until I added some
'scoreboard' forms and reports. I get the "Cannot open any more databases"
error.
The 'scoreboard' form show a matrix of 6 columns, 7 rows. Each cell is
calculated separate by (what I call complex) queries.
|
by: Mr.KisS |
last post by:
Hello.
I'm under Windows XP PRO SP1, IIS 5.1 ans SQL SERVER 2005
Express. When i try to open a connexion with :
<connectionStrings>
<add name="AppCnxStr"
connectionString="Server=KLEO\SQLEXPRESS;Integrated
Security=True;Database=C:\Program Files\Microsoft SQL
Server\MSSQL.1\MSSQL\Data\wizou.mdf"
providerName="System.Data.SqlClient" />
|
by: Mr.KisS |
last post by:
Hello.
I'm under Windows XP PRO SP1, IIS 5.1 ans SQL SERVER 2005
Express. When i try to open a connexion with :
<connectionStrings>
<add name="AppCnxStr"
connectionString="Server=KLEO\SQLEXPRESS;Integrated
Security=True;Database=C:\Program Files\Microsoft SQL
Server\MSSQL.1\MSSQL\Data\wizou.mdf"
providerName="System.Data.SqlClient" />
|
by: Mathew Butler |
last post by:
I'm investigating an issue I have when pulling data back from MS access I'm retrieving all rows from a column in a table of 5000 rows - accessing a column of type "memo" ( can be 65353 character long) . I'm pulling the data back using ODBC. Details are:
Microsoft Access Driver 4.00.6306.00
Jet 4.0 release level that is currently installed (Msjet40.dll ) "Microsoft Jet Engine Library" 4.0.9025.0
After 291 rows are retreived I am...
|
by: Joanne |
last post by:
I have searched through previous threads regarding this error. I went
back through all my code to make sure I closed and set to nothing all
open db's and rs's. However, I still have one computer getting this
error. This problem does not occur with any other users - some of whom
use the database continuously.
The user logs in, then goes to the Add Invoice form - it's a fairly
simple form, single table recordset with a subform based on...
| |
by: bhushan11 |
last post by:
hello sir
i am searching in your site but i dont get how to place question about visual c++.
so i am post this vc++ question in .net , sorre about that
i am working on visual c++ lang. but i nave some problem.
Linking...
LINK : fatal error LNK1104: cannot open file "ProfUIS223md.lib"
Error executing link.exe.
|
by: alex21 |
last post by:
Ok i am trying to use a Linq query to access a dictionary.
public static Dictionary<string, Client> Clients = new Dictionary<string, Client>();Using this Linq query:
IEnumerable<Staff> loginquery = from staff in Database.Staff where staff.Value.Passcode == txt_password.Text select staff;but i get the error
Error 2 Cannot implicitly convert type...
|
by: scubak1w1 |
last post by:
Hello,
Did a search here, manuals and Googled, etc generally, so apologies if I did not find the answer to my issue - that is, I try and 'self help' as mush as I can...
I adjusted my postgresql.conf file to set as on 'explain_pretty_print'
Now in pgAdmin (1.10.0) when I right-click a database in the 'usual' way, Maintenance, any of the tasks, its starts OK, but I get a dialogue box up every (seeming) operation that the Maintenance is...
|
by: Carruthers Pen |
last post by:
The command to open outlook is below:
conPATH_TO_OUTLOOK is C:\Program Files\Microsoft Office\Office14\outlook.exe
retVal = Shell(conPATH_TO_OUTLOOK, vbMaximizedFocus)
the error message is "cannot open your default e-mail folders. the infomation store could not be opened"
If I go to the path target and click on outlook.exe then it opens without any problems
it would seem that my user info is not being transmitted
I am using windows7...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |