输入字符串格式不正确 [英] input sting was not in correct format
本文介绍了输入字符串格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI,
在将数据插入数据库时,我将错误作为输入格式.
我在存储过程中也将所有表列数据类型都声明为varchar.
我的存储过程是.
At the time of inserting the data into database i''m getting the error as input format.
i declared all my table columns data type as varchar in stored procedure also.
My Stored Procedure is.
ALTER Procedure [dbo].[Ins_Upd_Students](@Sno varchar(50),@Sname varchar(50),@Class Int,@Fees varchar(50))
As
Begin
If Not Exists(Select Sno From Students Where Sno=@Sno)
Insert Into Stud(Sno,Sname,Class,Fees)
Values(@Sno,@Sname,@Class,@Fees)
Else
Update Stud Set Sname=@Sname,Class=@Class,Fees=@Fees Where Sno=@Sno
End
我的插入按钮代码是:
My Insert Button Code Is:
private void button3_Click(object sender, EventArgs e)
{
try
{
cmd.Parameters.Clear();
cmd.CommandText = "Ins_Upd_Students";
cmd.Parameters.AddWithValue("@Sno", Convert.ToInt32(textBox1.Text));
cmd.Parameters.AddWithValue("@Sname", Convert.ToInt32(textBox2.Text));
cmd.Parameters.AddWithValue("@Class",Convert.ToInt32(textBox3.Text));
cmd.Parameters.AddWithValue("@Fees", Convert.ToInt32(textBox4.Text));
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Executed");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
任何人都可以帮助我如何克服该错误.
非常感谢您
Can any one help me how to overcome that error.
thank u so much
推荐答案
如果您检查了表中的所有内容都是varchar(根据字段名称实际上听起来很糟糕),然后不要将数据转换为int.试试:
If you checked and everything is varchar in the table (which actually sounds bad based on the field names), then don''t convert the data to int. Try:
cmd.Parameters.AddWithValue("@Sno", textBox1.Text);
cmd.Parameters.AddWithValue("@Sname", textBox2.Text);
cmd.Parameters.AddWithValue("@Class"textBox3.Text);
cmd.Parameters.AddWithValue("@Fees", textBox4.Text);
但是,由于您有一个整数作为参数,因此您的过程出现了问题,所以代替了:
However, then you have an issue with your procedure since you have an integer as a parameter so instead of:
ALTER Procedure [dbo].[Ins_Upd_Students](@Sno varchar(50),@Sname varchar(50),@Class Int,@Fees varchar(50))
使用
use
ALTER Procedure [dbo].[Ins_Upd_Students](@Sno varchar(50),@Sname varchar(50),@Class varchar(50),@Fees varchar(50))
同样,这仅在Stud
表
Again, this applies only if all of those columns really are varchar in the Stud
table
名称= @ Sname,Class = @ Class,Fees = @ Fees其中Sno = @ Sno
看来您的一列不是varchar
(可能是fees
或Sno
).
检查表架构以找出正在使用的类型.
name=@Sname,Class=@Class,Fees=@Fees Where Sno=@Sno
Looks like one of your columns is notvarchar
(probablyfees
orSno
).
Check the table schema to figure out what types are being used.
这篇关于输入字符串格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文