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

I am trying to insert into a DB

I am trying to insert into a SQL DB but it is not working...I ran the query in SQL management studio which was the following:

Expand|Select|Wrap|Line Numbers
  1. SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Cycle"].ConnectionString);
  2.                     SqlCommand comm = new SqlCommand("INSERT into [CyclistDetails] (Surname, FirstName, PostalAddress, MobileNumber, EmailAddress, EmailConfirmed, NextOfKin, AccLimerick, AccGalway, TransportToCork, BikeTransportToDublin, BikeTransportToCork, ShirtSize, DietRequirements, AttendingBBQ, ParticipatedBefore, HearOfEvent, LevelOfCycling, TermsAndConditions) VALUES (@c_Surname,@c_FirstName,@c_PostalAddress,@c_MobileNumber,@c_EmailAddress,@c_EmailAddressConfirmed,@c_NextOfKin,@c_AccLimerick,@c_AccGalway,@c_TransportToCork,@c_BikeTransportToDublin,@c_BikeTransportToCork,@c_ShirtSize,@c_DietRequirements,@c_AttendingBBQ,@c_ParticipatedBefore,@c_HearOfEvent,@c_LevelOfCycling,@c_TermsAndConditions)", conn);
  3.  
  4.                     comm.Parameters.Add("@c_Surname", SqlDbType.NVarChar).Value = txtSname.Text;
  5.                     comm.Parameters.Add("@c_FirstName", SqlDbType.NVarChar).Value = txtFname.Text;
  6.  
  7.                     string address;
  8.                     address = txtAddress1.Text + "," + txtAddress2.Text + "," + txtAddress3.Text + "," + txtAddress4.Text;
  9.  
  10.                     comm.Parameters.Add("@c_PostalAddress", SqlDbType.NVarChar).Value = address.ToString();
  11.                     comm.Parameters.Add("@c_MobileNumber", SqlDbType.Int).Value = Convert.ToInt32(txtMobile.Text);
  12.                     comm.Parameters.Add("@c_EmailAddress", SqlDbType.NVarChar).Value = txtEmail.Text;
  13.                     comm.Parameters.Add("@c_EmailAddressConfirmed", SqlDbType.NVarChar).Value = txtEmail2.Text;
  14.                     comm.Parameters.Add("@c_NextOfKin", SqlDbType.Int).Value = Convert.ToInt32(txtNextOfKin.Text);
  15.                     comm.Parameters.Add("@c_AccLimerick", SqlDbType.NVarChar).Value = ddlAccLimerick.Text;
  16.                     comm.Parameters.Add("@c_AccGalway", SqlDbType.NVarChar).Value = ddlAccGalway.Text;
  17.                     comm.Parameters.Add("@c_TransportToCork", SqlDbType.NVarChar).Value = ddlTransportCork.Text;
  18.                     comm.Parameters.Add("@c_BikeTransportToDublin", SqlDbType.NVarChar).Value = ddlBikeTransportToDublin.Text;
  19.                     comm.Parameters.Add("@c_BikeTransportToCork", SqlDbType.NVarChar).Value = ddlBikeTransportCork.Text;
  20.                     comm.Parameters.Add("@c_ShirtSize", SqlDbType.NVarChar).Value = ddlShirtSize.Text;
  21.                     comm.Parameters.Add("@c_DietRequirements", SqlDbType.NVarChar).Value = ddlDiet.Text;
  22.                     comm.Parameters.Add("@c_AttendingBBQ", SqlDbType.NVarChar).Value = ddlBBQ.Text;
  23.                     comm.Parameters.Add("@c_ParticipatedBefore", SqlDbType.NVarChar).Value = ddlParticipatedBefore.Text;
  24.                     comm.Parameters.Add("@c_HearOfEvent", SqlDbType.NVarChar).Value = ddlHearOfEvent.Text;
  25.                     comm.Parameters.Add("@c_LevelOfCycling", SqlDbType.NVarChar).Value = ddlLevelOfCycling.Text;
  26.                     comm.Parameters.Add("@c_TermsAndConditions", SqlDbType.NVarChar).Value = CheckBox1.Text;
  27.  
  28.  
  29.  
  30.                     conn.Open();
  31.                     comm.ExecuteNonQuery();
  32.                     conn.Close();
  33.  
  34.  

And i got the following errors and my Data is not going into the DB:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '='.
Msg 103, Level 15, State 4, Line 2
The identifier that starts with 'INSERT into [CyclistDetails] (Surname, FirstName, PostalAddress, MobileNumber, EmailAddress, EmailConfirmed, NextOfKin, AccLimer' is too long. Maximum length is 128.
Feb 5 '10 #1
2 2577
tlhintoq
3,525 Expert 2GB
Database How-to parts 1 and 2
Database tutorial Part 1
Database tutorial Part 2
Feb 5 '10 #2
Curtis Rutland
3,256 Expert 2GB
I'm not a SQL expert, but this problem has something to do with quoted identifiers.

Try making a stored procedure for your Insert and calling that instead of a raw sql statement.
Feb 5 '10 #3

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

Similar topics

11
by: Jean-Christian Imbeault | last post by:
I have a table with a primary field and a few other fields. What is the fastest way to do an insert into that table assuming that sometimes I might try to insert a record with a duplicate primary...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
4
by: Arpan | last post by:
A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB" (datetime). Now when I am trying to add a new row using the...
5
by: .Net Sports | last post by:
I'm trying to insert records into an sql database coming from a page using the request ..form method. The table "general" has a primary key 'geid .' I get the following error: Cannot insert the...
2
by: =?Utf-8?B?Y2F0?= | last post by:
We recently moved an older ASP.NET 1.1 code base on to ASP.NET 2.0, .NET 3.0 and Windows 2003 Server SP2. We started experiencing the following issue with the web cache (the code is straightforward...
5
by: alivip | last post by:
How can I get every Token (word) and PreviousToken(Previous word) From multube files and frequency of each two word my code is trying to get all single word and double word (every Token (word) and...
5
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration:...
6
by: pbd22 | last post by:
Hi. I am trying to insert a zero into the below table and I am being told that: Cannot insert the value NULL into column 'UsageToday', table DB.dbo.Pub_Count'; column does not allow nulls....
10
by: albertaw1988 | last post by:
I'm trying to solve a numerical problem. Ordinary Differential Equation and this problem have 3 methods to solve it. I've type out 3 individual method and try to combine them into 1 code. I'm using...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
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...
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,...

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.