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;

R ACHUTHA181 reputationPosted Oct 25, 2012, 4:16 AM EDT
cmd.Parameters.Add(new SqlParameter("@Mobile", Convert.ToInt32(txt_mobile.Text)));
Shivanand ArurRank #920 · 2.3K reputationPosted Oct 25, 2012, 4:17 AM EDT
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
Neha SharmaRank #569 · 4.3K reputationPosted Oct 25, 2012, 4:29 AM EDT
Shivanand ArurRank #920 · 2.3K reputationPosted Oct 25, 2012, 4:38 AM EDT
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.
Vithal WadjeRank #19 · 47.2K reputationPosted Oct 25, 2012, 4:44 AM EDT
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();