473,406 Members | 2,620 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,406 software developers and data experts.

Problem inserting data .net

109 100+
Hi all I am getting this error message while try to insert data using my .net webform.

Expand|Select|Wrap|Line Numbers
  1. Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '1'.
  2.  
  3. Source Error: 
  4.  
  5. An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
  6.  
  7. Stack Trace: 
  8.  
  9.  
  10. [SqlException: Line 1: Incorrect syntax near '1'.]
  11.    System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +180
  12.    QualityQI.WebForm1.btnadd_Click(Object sender, EventArgs e) +1756
  13.    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
  14.    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
  15.    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
  16.    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
  17.    System.Web.UI.Page.ProcessRequestMain() +1292
  18.  
  19.  
  20.  
I'll appreciate all yours help.

Thank You,

and my insert command is:

Expand|Select|Wrap|Line Numbers
  1. SqlCommand cmd = new SqlCommand();
  2.             cmd.Connection = sqlConnection1;
  3.             cmd.Connection.Open();
  4.             cmd.CommandText = "insert into gingercqi (QI_TRACK,DATE_RCV,INC_NUM,INC_DATE,INC_TIME,QANUM,BASE_HSP,ISSUE_IDENTIFY,MICN_INVOLVED,1ST_RESP1,1ST_RESP2,TRANSPORT1,INVESTIGATE,DATE_ASSIGN,CNE,DATE_CNE,INVPARTY1,INVPARTY2,INVPARTY3,INVPARTY4,OTHERINV,ISSUECATEGORY,ISSUEMEMO,QILEVEL,PACREPORTABLE,PACOUTCOME,CLOSEDATE,RES_CATEGORY,RES_MEMO,DISCIPLINE,DISC_TYPE,MD_REVIEW,POLICY_VIOLATION) VALUES ('"+txtqitrack.Text+"','"+Datercv.SelectedDate+"','"+ txtincnum.Text+"','"+ Dateinc.SelectedDate+"','"+txtinctime.Text+"','"+txtqanum.Text+"','"+dpbasehsp.SelectedValue+"','"+dpissueidentify.SelectedValue+"','"+txtmicninvl.Text+"','"+txt1stresp1.Text+"','"+txt1stresp2.Text+"','"+txttransport1.Text+"','"+dpinvestigate.SelectedValue+"','"+Dateasn.SelectedDate+"','"+dpcne.SelectedValue+"','"+Datecne.SelectedDate+"','"+dpinvlparty1.SelectedValue+"','"+dpinvlparty2.SelectedValue+"','"+dpinvlparty3.SelectedValue+"','"+dpinvlparty4.SelectedValue+"','"+txtotherinvl.Text+"','"+dpissuecate.SelectedValue+"','"+txtissuememo.Text+"','"+dpqilevel.SelectedValue+"','"+chkpacreport.Checked+"','"+txtpacoutcome.Text+"','"+Dateclose.SelectedDate+"','"+dpreslcate.SelectedValue+"','"+txtresolutionmemo.Text+"','"+chkdiscipline.Checked+"','"+txtdisctype.Text+"','"+chkmdreview.Checked+"','"+chkpolicyvio.Checked+"')";
  5.             cmd.ExecuteNonQuery();
  6.             cmd.Connection.Close();
  7.  
Nov 29 '07 #1
6 1123
Shashi Sadasivan
1,435 Expert 1GB
Hi arial,
As a good gesture, could you please run the program in debug mode, place a break point at where the commandtext is being created, and get the actaul text generated there.

Will help out debugging that.
It seems to be a syntax error with the sql statement

edit: Could you replace "1ST_RESP1,1ST_RESP2" in the field names to
[1ST_RESP1],[1ST_RESP2]

the square brackets lets sql know that it is a field name (field names generally do not start with number, or contain spaces, but the square brackets skips these constraints)
Nov 29 '07 #2
arial
109 100+
Thank Shashi.

You have been a great help.

The error I am getting while inserting checkbox value.

Which I am inserting like '"+chkmdreview.checked+"'.

Is it a correct way to insert check box value?

Thank You,
Nov 29 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
you will have to explicityly convert the checked value to zero or one.
With the above way, it will be converted to "true" or "false", while what you need to do it convert it to 0 or 1
Nov 29 '07 #4
arial
109 100+
actually that is what I need to insert in database like true or false so, in database "T " for true and "F" for false.

how can I accomplish this?

Thank You,
Nov 29 '07 #5
Shashi Sadasivan
1,435 Expert 1GB
If you represent true and false using a varchar 'T' or 'F'
then use if statements !!!!
Nov 29 '07 #6
arial
109 100+
Thank You Shashi for you help.

So, this is what I did.

My datafield in database is char(1).

I put in my code.
Expand|Select|Wrap|Line Numbers
  1. string md="";
  2.  
  3. if(chkpolicyvio.checked)
  4.        md = "T";
  5.  
  6. else
  7.     md = "F";
  8. insert into table (policyvio) values ('"+Convert.ToChar(md)+"')
  9.  
this gives me error message.

Error converting data type varchar to numeric.

Please help me.

Thank You,
Nov 29 '07 #7

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

Similar topics

8
by: Alban Hertroys | last post by:
Hello, I'm using psycopg to insert records in a number of threads. After the threads finish, another thread runs to collect the inserted data. Now, my problem is that psycopg let's my threads...
7
by: middletree | last post by:
Posted this to Access group, meant to do it here: I have what I call a composite table. Can't recall what they called it in database class, but it's where you take the PK of two different...
1
by: David A. Caballero J. | last post by:
I have a 3 layer system, SQL Server 2000 database, COM+ dll's (VC++ 6) and ASP frontend, this system has been in production for quite some time using english, spanish and portuguese versions. Now...
2
by: altergothen | last post by:
Hi there I am a newbie to ASP.Net - Please Help! I am trying to insert the values of my variables into a database. If I try the following it works perfectly: string insertQuery = "INSERT into...
2
by: pramod | last post by:
Hi I am facing the problem while inserting the spanish characters in the DB2 UDB v8.2 database. We are pulling the data from SQL server through informatica and then pushing the same in the DB2...
8
by: Godzilla | last post by:
Dear all, I cannot find a solution for my problem with inserting a blob object (>4000 in length) into an ORACLE database via ODBC. I have tried the two ways of inserting the blob object (a...
3
by: Surya | last post by:
Dear All, I have problem on inserting a record to database..Although it looked easy.. i have caught up with following issue .. please go ahead and help me to find solution I Need to insert...
18
by: boss1 | last post by:
Hi all, i m having a problem with inserting data in oracle db. When i use form action =(call self page) then data is inserting properly.But problem with when using form...
3
by: len | last post by:
Hi All I have started a little pet project to learn python and MySQL. The project involves figuring out all the combinations for a 5 number lottery and storing the data in a MySQL file. The...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
agi2029
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,...
0
isladogs
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...

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.