【发布时间】:2023-03-30 10:10:02
【问题描述】:
无法将参数值从 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;
【问题讨论】:
-
我认为您无法将电话号码转换为字节......也许是字节数组。为什么不更改数据库中的类型呢?见:stackoverflow.com/questions/75105/…
-
除了@Rufus L 的评论(这很棒,一个字节存储从 0 到 255,这对于北美区号来说甚至都不够大,更不用说完整的电话号码了),电话号码永远不应该以数字类型存储。如果您不需要对其进行数学运算,请不要将其存储为数字。从长远来看,它只会给你带来悲伤。
标签: c# asp.net sql-server-2008 ado.net