Reputation: 37
I dont know what is wrong with my code. please see below screenshot
can any one tell what is the issue? I am using visual studio 2010 coupled with Ms SQL 2008
Upvotes: 0
Views: 1263
Reputation: 856
Try this :
This will cover the proper way to insert the Data using Parameterized Queries
:
Dim cmd as new SqlCommand("INSERT INTO dbo.Employee(Fullname, Position, EmployeeNumber, Salary) Values (@Name, @Position, @Number, @Salary)", conn)
cmd.parameters.addWithValue("@Name", txtFullName.Text)
cmd.parameters.addWithValue("@Position", txtPosition.Text)
cmd.parameters.addWithValue("@EmployeeNumber", Integer.Parse(txtEmployeeNumber.Text)) 'Assuming You have employee number in integer
cmd.parameters.addWithValue("@Salary", Integer.Parse(txtSalary.Text)) 'Assuming You have employee number in integer
cmd.ExecuteNonQuery()
Feel free to ask if you have any doubts. And you will not get the above error unless you have different datatypes set in database.
Upvotes: 2
Reputation: 70
You have not specified id column in query.
OR mark id column as identity in employee table
Upvotes: -1
Reputation:
You are missing '}' closing at "{3}"
I am thinking that id column would be an auto incrementing value.
If not then you need to set this, or else if you have a non-nullable column, with no default value, if you provide no value it will throws an error.
To set up auto-increment in SQL Server Management Studio:
Step-1:Open your table in Design mode
Step-2:Select your column and go to Column Properties
Step-3:Under Indentity Specification, set Is Identity=Yes and Indentity Increment=1
Upvotes: 3