我想从int64转换为byte

时间:2015-03-23 23:30:48

标签: c# asp.net sql-server-2008 ado.net

无法将参数值从int32转换为字节 数据库代码

,数据库中的程序是:

背后的webform代码:

client c = new client();
c.name = Textbox_Addclient_first.Text + " " + Textbox_Addclient_second.Text + 
    " " + Textbox_Addclient_third.Text;
c.address = Textbox_addclientadress.Text;
c.phone = int.Parse(Textbox_addclientphone.Text);

班级代码是:

SqlCommand com = new SqlCommand("add_client", con);

com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@name", SqlDbType.NVarChar).Value = this.name;
com.Parameters.Add("@address", SqlDbType.NVarChar).Value = this.address;
com.Parameters.Add("@name", SqlDbType.TinyInt).Value = this.phone;
com.ExecuteNonQuery();
con.Close();

b = true;

1 个答案:

答案 0 :(得分:0)

这一行:

com.Parameters.Add("@name", SqlDbType.TinyInt).Value = this.phone;
  1. 您正尝试将手机对象传递给name参数。
  2. 你正在使用tinyint,varchar(10)会是一个更好的选择,但如果你坚持使用整数,int64就足够了。
  3. 如果您使用int来确保只传递数字,请使用“[0-9] {10}”对数字字符串进行正则表达式检查