简体   繁体   English

我想从int64转换为字节

[英]i want to convert from int64 to byte

failed to convert parameter value from int32 to a byte the database code 无法将参数值从int32转换为数据库代码的字节

and the procedure in database is: 数据库中的过程是:

The webform code behind: 后面的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);

The class code is: 类代码为:

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;

This line: 这行:

com.Parameters.Add("@name", SqlDbType.TinyInt).Value = this.phone;
  1. You are trying to pass the phone object to the name parameter. 您试图将电话对象传递给name参数。
  2. You are using tinyint, varchar(10) would be a better option but if you insist on using integer, int64 should suffice. 您使用tinyint,则varchar(10)是一个更好的选择,但是如果您坚持使用整数,则int64就足够了。
  3. If you are using int to make sure only digits are passed, do a regular expression check on the string for digits using "[0-9]{10}" 如果使用int来确保仅传递数字,请使用“ [0-9] {10}”对字符串进行正则表达式检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM