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

Error Incorrect syntax near ',' in asp.net

Hy,
I have wrote in asp.net the next code:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.SqlClient;
  8. public partial class Default2 : System.Web.UI.Page
  9. {
  10.     protected void Page_Load(object sender, EventArgs e)
  11.     {
  12.  
  13.     }
  14.     protected void Calendar1_SelectionChanged(object sender, EventArgs e)
  15.     {
  16.         TextBoxData.Text = Calendar1.SelectedDate.ToString();
  17.     }
  18.     protected void Button1_Click(object sender, EventArgs e)
  19.     {
  20.         try
  21.         {
  22.  
  23.             string connString = "Initial Catalog=PEOPLE;Data Source=John-4E29FADEE;Integrated Security=SSPI;";
  24.             SqlConnection conn = new SqlConnection(connString);
  25.             conn.Open();
  26.             Response.Write("Successful connection!");
  27.             SqlCommand comanda = new SqlCommand();
  28.             comanda.Connection = conn;
  29.             comanda.CommandType = System.Data.CommandType.Text;
  30.  
  31.             comanda.CommandText = "INSERT INTO dbo.PERSON VALUES (" + TextBoxID.Text + "," + TextBoxName.Text + "," + TextBoxInitiala.Text + "," + TextBoxLastName.Text + "," + TextBoxData.Text + "," + TextBoxCNP.Text + "," + TextBoxMother.Text + "," + TextBoxFather.Text + ")";
  32.             int no = comanda.ExecuteNonQuery();
  33.  
  34.             Response.Write("No of affected rows = " + no);
  35.             conn.Close();
  36.  
  37.         }
  38.         catch (SqlException exc)
  39.         {
  40.             Response.Write("Error " + exc.Message);
  41.         }
  42.  
  43.     }
  44.  
  45. }
And i get the message: Successful connection! Error Incorrect syntax near ','
I looked many times but I can not figure out what's wrong
Please help me
Oct 31 '13 #1
1 4679
psurvi
6
Your insert query must be changed as :
Expand|Select|Wrap|Line Numbers
  1. comanda.CommandText = "INSERT INTO dbo.PERSON VALUES (" + TextBoxID.Text + ",'" + TextBoxName.Text + "','" + TextBoxInitiala.Text + "','" + TextBoxLastName.Text + "','" + TextBoxData.Text + "','" + TextBoxCNP.Text + "','" + TextBoxMother.Text + "','" + TextBoxFather.Text + "')";
  2.  
assuming Name,Initials,Lastname,Data,BoxCNP,Mother,Father to be as varchar /string type in the database.

The format to insert/retrieve all string type declared values in the database from C# is
Expand|Select|Wrap|Line Numbers
  1. '"+ example.Text+"'
and for all fields declared in numeric category is
Expand|Select|Wrap|Line Numbers
  1. "+examplenumber.Text+"
.
Nov 19 '13 #2

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

Similar topics

1
by: Amit D.Shinde | last post by:
Hi Experts, i am writting a stored procedure in sql server 7. Its a simple stored procedure It is my first stored procedure. I want insert a record in table if the primary key field user id...
11
by: Mark Findlay | last post by:
Hello Experts! I am attempting to use the OleDbCommand.ExecuteScaler() function within my ASP.NET C# web page to perform a simple validation, but receive the following error: "Incorrect...
1
by: Dax | last post by:
When i insert some values float in a form made with ASP appear an error message like this: Microsoft OLE DB Provider for SQL Server (0x80040E14) Line 1: Incorrect syntax near ','. sql="select...
1
by: mabubakarpk | last post by:
HI. I am using SQL Server 2000. I generate a script of some table from EmpDB database when I run script in query analyzer it return error "Incorrect syntax near 'COLLATE'." Scripts is ...
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
2
by: Mark B | last post by:
When I click the 'Update' button on a ASP.Net 3.5 GridView record, I get an error: Incorrect syntax near 'nvarchar'. Everything else there works OK. Here is the code: <%@ Page...
1
by: Mia Archibald | last post by:
SELECT mcr2008.st, (SUM(mcr2008.bedsize)-SUM(mcr2007.bedsize))/SUM(mcr2007.bedsize) FROM ( ( SELECT mcrid, st , SUM(bedsize) as bedsize FROM MCRCR_96_to_08 WHERE...
2
by: silwar | last post by:
Hi, I have already stored value of author id in list item value while page loads. but when I change index of drop down list to view author information error is shown. I tried to debug using check...
2
by: juhii3102 | last post by:
protected void btn_Edit_Click(object sender, EventArgs e) { Panel1.Visible = true; Button5.Visible = true; if (FileUpload1.HasFile) { //string...
3
syedshaffee
by: syedshaffee | last post by:
Hey people, i am getting this error 'Incorrect syntax near the keyword 'EXISTS'.' while executing this query SELECT Contract_detail.Contract_no FROM Contract_detail INNER JOIN...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.