I have a stored procedure and I am getting this error when executing it from C# code.
Error converting data type nvarchar to int.
My stored procedure:
CREATE PROCEDURE [dbo].[donateBloodProc]
@donorName varchar(50),
@gender varchar(20),
@email varchar(50),
@bloodGroup varchar(50),
@contact_number int, @L_D_D date,
@city varchar(50),
@arid_number varchar(50),
@DepId int
AS
INSERT INTO
tblDonors(Dname, gender, bloodGroup, email, contact_number,
L_D_D,city,arid_number,DeptID,dateDonated)
VALUES
(@donorName,@gender,@bloodGroup,@email,@contact_number,
@L_D_D,@city,@arid_number,@DepId,GETDATE());
And this is my C# code:
SqlCommand commandForSP = new SqlCommand("donateBloodProc",DALobj.openConnection());
commandForSP.CommandType = System.Data.CommandType.StoredProcedure;
commandForSP.Parameters.AddWithValue("@donorName", TextBox1.Text);
commandForSP.Parameters.AddWithValue("@gender", RadioButtonList1.SelectedValue);
commandForSP.Parameters.AddWithValue("@email", TextBox5.Text);
commandForSP.Parameters.AddWithValue("@bloodGroup", DropDownList1.SelectedValue);
commandForSP.Parameters.AddWithValue("@contact_number", TextBox2.Text);
commandForSP.Parameters.AddWithValue("@L_D_D", TextBox3.Text);
commandForSP.Parameters.AddWithValue("@city", DropDownList2.SelectedValue);
commandForSP.Parameters.AddWithValue("@arid_number", TextBox1.Text);
commandForSP.Parameters.AddWithValue("@DepId", TextBox4.Text);
commandForSP.ExecuteNonQuery();
All the data types of the columns in my stored procedure are same as in my database table tblDonors
AddWithValuecausing problems. - Dour High Arch