0
我使用以下格式創建存儲過程。錯誤:輸入字符串格式不正確
ALTER procedure [spInsertEmp]
@empName varchar(50),
@Emp_Id int ,
@option varchar(10)
as
set nocount off
IF @option='delete'
delete from emp where [email protected]_Id
if @option='insert'
IF EXISTS(select EmpName from emp where [email protected])
return -1
ELSE
insert into emp (EmpName)values(@empName)
if @option='update'
begin
UPDATE emp set [email protected] where [email protected]_Id
End
在
我給代碼隱藏在使用C#像下面的格式
protected void btnupdate_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server = MYLAPTOP;uid=sa;pwd =hari_123; database =test1");
//conn.Open();
SqlCommand cmd = new SqlCommand("spInsertEmp", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@empName", SqlDbType.VarChar, 50).Value = txtAdditionalChargeType.Text;
cmd.Parameters.Add("@Emp_Id", SqlDbType.Int).Value =Convert.ToInt32(txtAdditionalChargeType1.Text);
cmd.Parameters.Add("@option", SqlDbType.VarChar, 10).Value = "update";
我得到錯誤此行
cmd.Parameters.Add("@Emp_Id", SqlDbType.Int).Value =Convert.ToInt32(txtAdditionalChargeType1.Text);
錯誤是
input string was not in a correct format
所以任何人都可以幫助我給出更新按鈕代碼屬於上述存儲過程。請幫幫我。
如果字符串包含alphabhets,並且包含數字,那麼您不能將字符串轉換爲int。 – Malcolm 2010-07-01 06:34:54
這個帖子不應該被標記爲Silverlight。最好使用SQL StoredProcedre和.net – 2010-07-01 07:00:55