473,385 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

INSERT INTO error

string sql = string.Format("INSERT INTO tbluser(user,pasw,tanya,jawab)VALUES('{0}','{1}',' {2}','{3}')", TBuser.Text, TBpassword.Text, CBboxpertanyaan.SelectedItem, TBjawaban.Text);
OleDbConnection connect = new OleDbConnection(koneksi);
connect.Open();
OleDbCommand cmd = new OleDbCommand(sql, connect);
cmd.ExecuteNonQuery();



I really sure my syntax is work.
but when i run it, visual studio said that there's syntax error in INSERT INTO statement. What should I do?
please help -__-
Jan 8 '12 #1
2 1533
Rabbit
12,516 Expert Mod 8TB
What's the resulting SQL string look like?
Jan 9 '12 #2
adriancs
122 100+
it receive direct input from textbox.
you might need to filter out the escape character for safe sql string.
for example, if the text from the textbox input contains the symbol of
this
Expand|Select|Wrap|Line Numbers
  1. '
or this symbol
Expand|Select|Wrap|Line Numbers
  1. ;
you'll get an syntax error.
you need to replace
Expand|Select|Wrap|Line Numbers
  1. '
with a slash and become this
Expand|Select|Wrap|Line Numbers
  1. \'
and replace
Expand|Select|Wrap|Line Numbers
  1. CBboxpertanyaan.SelectedItem
with
Expand|Select|Wrap|Line Numbers
  1. CBboxpertanyaan.SelectedItem + ""
or
Expand|Select|Wrap|Line Numbers
  1. CBboxpertanyaan.SelectedItem.ToString()
Jan 12 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Murali Kanaga | last post by:
Greetings! When I run the following SQL statement in Perl, I get an error stating: any help/pointers how this can be resolved? Thanks, -Murali SQL note_insert error: "There are more...
1
by: INSERT ERROR | last post by:
I am trying to INSERT record in MYSQL database, but each time the code tries to execute the command: MySQL_cmdGLAccount.ExecuteNonQuery(), it reports an error with the message "COLUMN COUNT...
3
by: INSERT ERROR | last post by:
I am trying to INSERT record in MYSQL database, but each time the code tries to execute the command: MySQL_cmdGLAccount.ExecuteNonQuery(), it reports an error with the message "COLUMN COUNT...
8
by: erin.sebastian | last post by:
Hi all, I have a really silly problem that i can't find the answer too. I am working with VB.NET and i am trying to insert a new record into my access database (pretty easy right?) well i am...
3
by: phil2phil | last post by:
Hi, I'm working on an asp where I wanted to do a simple insert using data from another table, structure is: Table A has columns - ID, Code, Type Table B has columns - key, FName, LNAme, DOB, cd,...
3
by: siamesedream | last post by:
Hello, I'm having trouble using the insert method of an ObjectDataSource that uses a custom DataObjectType. If I'm using a custom DataObjectType does my insert method have to take that object,...
2
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and...
0
by: Peter Nofelt | last post by:
Hi all, ISSUE: ==================== In SQL 2005 (sp2) I get the following error when preforming a bulk insert with an associated xml format file: "Could not bulk insert. Unknown version of...
3
by: Greg Corradini | last post by:
Hello, I'm trying to perform a simple insert statement into a table called Parcel_Test (see code below). Yet, I get an error message that I've never seen before (see traceback below). I've tried...
2
by: Greg Corradini | last post by:
Hello, I've never gotten this traceback error before using mx.ODBC. Any ideas about resolving this issue? The statement and the error it generates are listed below. curse.execute("Insert into...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.