Trying to insert data into SQL Server database using asp.net web application, getting an error

ACostea

I am using Visual Studio to create an asp.net web application in C# and am having issues trying to insert data from one of my pages into a table in a SQL Server database. I am getting the following error message:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: The variable name '@' has already been declared. Variable names must be unique within a query batch or stored procedure.

My code looks like this;

Block of code

I have tried a few different things but I keep getting the same error and I've been on here and youtube for nearly an hour now and I can't find anything that relates to my issue. Any help would be greatly appreciated.

Thanks!

Edit: I should add that I got this code from youtube and in the video, it worked fine. The only real difference is that my version is within an 'if' statement. I commented the if statement out and received the same error message.

PoweredByOrange

You code is wrong. First, your sql query is incomplete; you need to include the actual variable names as part of your INSERT script:

INSERT INTO parent(parentID) VALUES (@parentID)

Then in your C# code, you need to include the exact name of the parameter when adding it to the collection:

xp.Parameters.AddWithValue("@parentID", userBox.Text);

This is obviously for one parameter, you'll need to repeat the same pattern for the rest. Read more here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Cannot Insert data into SQL Server database using a asp.net web app

From Dev

Insert Excel data to SQL server using ASP.NET MVC

From Dev

Getting HTTP ERROR: 503 while trying to load the web application using Jetty server

From Dev

Data not getting inserted into mysql database in asp.net c# web application

From Dev

Open connection trouble when trying to insert data into SQL Server database

From Dev

Insert image to local SQL Server database in ASP.NET

From Dev

How to insert into a SQL Server CE database in asp.net

From Dev

"Invalid column name" when trying to insert data into database using SQL

From Dev

"Invalid column name" when trying to insert data into database using SQL

From Dev

ASP.net web forms app "on server" getting old data values using Entity framework

From Dev

How to insert data from 2 different sources into 2 different tables in SQL server using Web application?

From Dev

Exception Error in trying to update database using asp.net

From Dev

ASP.NET Webjobs error accessing the web application EF database

From Dev

Trying to insert data in SQL server from Android app using WebService

From Dev

Trying to insert data in SQL server from Android app using WebService

From Dev

ASP.NET connection string to local SQL Server database, using web.config

From Dev

C#/ASP.NET Web Site using SQL Server CE Database Slow Query

From Dev

Insert data into local database using ado.net in a console application

From Dev

Insert data in a database table using Asp.net

From Dev

How to insert data into two SQL Server tables in asp.net

From Dev

Getting error on like operator in ASP.NET with SQL Server

From Dev

Writing data and saving to a SQL Server database using C# and ASP.NET

From Dev

Insert values into SQL Server using asp.net

From Dev

Getting a NullPointerException when trying to insert using SQL

From Dev

I have a swing application using Netbeans. I am trying to insert user object to the database table. But I am getting following error

From Dev

Connecting to SQL Server Database using a Hosted Web Application

From Dev

ASP.net Getting the error "Access to the path is denied." while trying to upload files to my Windows Server 2008 R2 Web server

From Dev

Error while trying to insert data into database using hibernate. error is Constraint Violation exception (using Oracle DB)

From Dev

.Net C# Input string was not in a correct format. Trying to insert value into SQL Server database

Related Related

  1. 1

    Cannot Insert data into SQL Server database using a asp.net web app

  2. 2

    Insert Excel data to SQL server using ASP.NET MVC

  3. 3

    Getting HTTP ERROR: 503 while trying to load the web application using Jetty server

  4. 4

    Data not getting inserted into mysql database in asp.net c# web application

  5. 5

    Open connection trouble when trying to insert data into SQL Server database

  6. 6

    Insert image to local SQL Server database in ASP.NET

  7. 7

    How to insert into a SQL Server CE database in asp.net

  8. 8

    "Invalid column name" when trying to insert data into database using SQL

  9. 9

    "Invalid column name" when trying to insert data into database using SQL

  10. 10

    ASP.net web forms app "on server" getting old data values using Entity framework

  11. 11

    How to insert data from 2 different sources into 2 different tables in SQL server using Web application?

  12. 12

    Exception Error in trying to update database using asp.net

  13. 13

    ASP.NET Webjobs error accessing the web application EF database

  14. 14

    Trying to insert data in SQL server from Android app using WebService

  15. 15

    Trying to insert data in SQL server from Android app using WebService

  16. 16

    ASP.NET connection string to local SQL Server database, using web.config

  17. 17

    C#/ASP.NET Web Site using SQL Server CE Database Slow Query

  18. 18

    Insert data into local database using ado.net in a console application

  19. 19

    Insert data in a database table using Asp.net

  20. 20

    How to insert data into two SQL Server tables in asp.net

  21. 21

    Getting error on like operator in ASP.NET with SQL Server

  22. 22

    Writing data and saving to a SQL Server database using C# and ASP.NET

  23. 23

    Insert values into SQL Server using asp.net

  24. 24

    Getting a NullPointerException when trying to insert using SQL

  25. 25

    I have a swing application using Netbeans. I am trying to insert user object to the database table. But I am getting following error

  26. 26

    Connecting to SQL Server Database using a Hosted Web Application

  27. 27

    ASP.net Getting the error "Access to the path is denied." while trying to upload files to my Windows Server 2008 R2 Web server

  28. 28

    Error while trying to insert data into database using hibernate. error is Constraint Violation exception (using Oracle DB)

  29. 29

    .Net C# Input string was not in a correct format. Trying to insert value into SQL Server database

HotTag

Archive