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: - SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Cycle"].ConnectionString);
-
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);
-
-
comm.Parameters.Add("@c_Surname", SqlDbType.NVarChar).Value = txtSname.Text;
-
comm.Parameters.Add("@c_FirstName", SqlDbType.NVarChar).Value = txtFname.Text;
-
-
string address;
-
address = txtAddress1.Text + "," + txtAddress2.Text + "," + txtAddress3.Text + "," + txtAddress4.Text;
-
-
comm.Parameters.Add("@c_PostalAddress", SqlDbType.NVarChar).Value = address.ToString();
-
comm.Parameters.Add("@c_MobileNumber", SqlDbType.Int).Value = Convert.ToInt32(txtMobile.Text);
-
comm.Parameters.Add("@c_EmailAddress", SqlDbType.NVarChar).Value = txtEmail.Text;
-
comm.Parameters.Add("@c_EmailAddressConfirmed", SqlDbType.NVarChar).Value = txtEmail2.Text;
-
comm.Parameters.Add("@c_NextOfKin", SqlDbType.Int).Value = Convert.ToInt32(txtNextOfKin.Text);
-
comm.Parameters.Add("@c_AccLimerick", SqlDbType.NVarChar).Value = ddlAccLimerick.Text;
-
comm.Parameters.Add("@c_AccGalway", SqlDbType.NVarChar).Value = ddlAccGalway.Text;
-
comm.Parameters.Add("@c_TransportToCork", SqlDbType.NVarChar).Value = ddlTransportCork.Text;
-
comm.Parameters.Add("@c_BikeTransportToDublin", SqlDbType.NVarChar).Value = ddlBikeTransportToDublin.Text;
-
comm.Parameters.Add("@c_BikeTransportToCork", SqlDbType.NVarChar).Value = ddlBikeTransportCork.Text;
-
comm.Parameters.Add("@c_ShirtSize", SqlDbType.NVarChar).Value = ddlShirtSize.Text;
-
comm.Parameters.Add("@c_DietRequirements", SqlDbType.NVarChar).Value = ddlDiet.Text;
-
comm.Parameters.Add("@c_AttendingBBQ", SqlDbType.NVarChar).Value = ddlBBQ.Text;
-
comm.Parameters.Add("@c_ParticipatedBefore", SqlDbType.NVarChar).Value = ddlParticipatedBefore.Text;
-
comm.Parameters.Add("@c_HearOfEvent", SqlDbType.NVarChar).Value = ddlHearOfEvent.Text;
-
comm.Parameters.Add("@c_LevelOfCycling", SqlDbType.NVarChar).Value = ddlLevelOfCycling.Text;
-
comm.Parameters.Add("@c_TermsAndConditions", SqlDbType.NVarChar).Value = CheckBox1.Text;
-
-
-
-
conn.Open();
-
comm.ExecuteNonQuery();
-
conn.Close();
-
-
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.
2 2577
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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....
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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...
|
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...
|
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...
|
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,...
| |