Name txt_name
Employeeid Textbox2
Dept checkboxlist1
checkboxlist2
Gender Radiobuttionlist1
Radiobuttionlist2
DOB dropdown
Mobileno txt_mobile
email txt_emailid
Address txt_address
I have one insert button.
con = new SqlConnection("Server=(local);initial catalog=master;Trusted_Connection=True");
con.Open();
SqlCommand cmd = new SqlCommand("Reg", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Empid", TextBox2.Text));
cmd.Parameters.Add(new SqlParameter("@Name", txt_name.Text));
cmd.Parameters.Add(new SqlParameter("@Dept", CheckBoxList1.Text));
cmd.Parameters.Add(new SqlParameter("@Gender", RadioButtonList1.Text));
cmd.Parameters.Add(new SqlParameter("@DOB", Calendar1.TodaysDate));
cmd.Parameters.Add(new SqlParameter("@Mobile", txt_mobile.Text));
cmd.Parameters.Add(new SqlParameter("@Email", txt_emailid.Text));
cmd.Parameters.Add(new SqlParameter("@Address", txt_address.Text));
cmd.ExecuteNonQuery();
con.Close();
Creating Store Procedure code as follows
CREATE Procedure Reg
@Name varchar(50),
@Empid varchar(50),
@Dept varchar(50),
@Gender varchar(50),
@DOB varchar(50),
@Mobile int,
@Email Varchar(50),
@Address Varchar(50)
AS
BEGIN
INSERT INTO Registration VALUES(@Name,@Empid,@Dept,@Gender,@DOB,@Mobile,@Email,@Address)
END
GO
Database table design as follows;
Name varchar
Empid varchar
Dept varchar
Gender varchar
DOB varchar
Mobile int
Email varchar
Address varchar
WHEN I RUN FOLLOWING ERROR OCCURS AS FOLLOWS;
Vithal WadjePosted Oct 25, 2012, 8:44 AM
SqlCommand com = new SqlCommand("tablename", entry.con);
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "Sp_activityuser";
com.Parameters.AddWithValue("@Name",Textname.Text).ToString();
com.Parameters.AddWithValue("@moblemumber",Textcode.Text).ToString();
com.ExecuteNonQuery();
Shivanand ArurPosted Oct 25, 2012, 8:38 AM
Do it this way...
ALTER TABLE Registration
ALTER COLUMN Mobile VARCHAR(10)
Hope this helps u...
Please mark any of these answers as accepted if it helped!!!
Thank you.
Neha SharmaPosted Oct 25, 2012, 8:29 AM
Shivanand ArurPosted Oct 25, 2012, 8:17 AM
Something like this...
int MobNo = Convert.ToInt32(txt_mobile.Text);
and then add this int "MobNo" in the Parameter...
Can u also tell me where exactly are getting the issue... I mean on which line???
Try out the solution given by me.. May be it will work
Thanks
R ACHUTHAPosted Oct 25, 2012, 8:16 AM
cmd.Parameters.Add(new SqlParameter("@Mobile", Convert.ToInt32(txt_mobile.Text)));