将数据类型 nvarchar 转换为 bigint 时出错

发布于 2024-09-25 19:47:25 字数 3033 浏览 2 评论 0原文

此代码给我错误:

error in converting datatype nvarchar to bigint

这是我的表值:

   @customer_first_name nvarchar(50),
@customer_last_name nvarchar(50),
@customer_address nvarchar(max),
@gender nchar(10),
@date_of_birth datetime,
@customer_email_id varchar(50),
@customer_occuption varchar(50),
@customer_phone_number Bigint,
@nominee_name nchar(50),
@customer_id nvarchar(50),
@account_type nvarchar(50),
@account_number nvarchar(50),
@transfer_access_code nvarchar(50),
@account_balance Bigint,
@pin_code BigInt,
@nationality nvarchar(50),
@password nvarchar(50)
    
lblAmount.Text = HFamount .Value ;
int balamount = Convert.ToInt32(lblAmount.Text);
int Cpincode = Convert.ToInt32(txtpincode.Text);

long phone = Convert.ToInt64(txtphone.Text);
string cust_id = CUSTOMER_ID_GENERATOR();
string sqlquery = "INSERT INTO customer_details values(@customer_first_name,@customer_last_name,@customer_address,@gender,@date_of_birth,@customer_email_id,@customer_occuption,@customer_phone_number,@nominee_name,@customer_id,@account_type,@account_number,@transfer_access_code,@account_balance,@pin_code,@nationality,@password)";
string strconstring = ConfigurationManager.ConnectionStrings["ONLINE_BANKING2_ConnectionString"].ConnectionString;
SqlConnection mycon = new SqlConnection(strconstring);
mycon.Open();
SqlCommand  cmdRegister= new SqlCommand(sqlquery,mycon);
cmdRegister.Parameters.Add(new SqlParameter("@customer_first_name",txtcustname.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@customer_last_name",txtcustlastname.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@customer_address",txtAddress.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@gender", rbtngender.SelectedItem.Value.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@date_of_birth", txtDOB.Text));
cmdRegister.Parameters.Add(new SqlParameter("@customer_email_id", txtemail.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@customer_occuption",  txtcustoccupation.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@customer_phone_number",  phone));
cmdRegister.Parameters.Add(new SqlParameter("@nominee_name",  txtnominee.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@customer_id",  cust_id));
cmdRegister.Parameters.Add(new SqlParameter("@account_type",  accType.SelectedItem.Value.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@account_number",  ACCOUNT_NUMBER_GENERATOR()));
cmdRegister.Parameters.Add(new SqlParameter("@transfer_access_code",Transfer_code()));
cmdRegister.Parameters.Add(new SqlParameter("@account_balance",  balamount));
cmdRegister.Parameters.Add(new SqlParameter("@pin_code",  Cpincode));
cmdRegister.Parameters.Add(new SqlParameter("@nationality", DropCountry.SelectedItem.Value.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@password",txtpasswd2.Text.ToString()));
cmdRegister.ExecuteNonQuery();
mycon.Close();

请帮助我

只查看回复

this code is giving me error:

error in converting datatype nvarchar to bigint

this is my table values:

   @customer_first_name nvarchar(50),
@customer_last_name nvarchar(50),
@customer_address nvarchar(max),
@gender nchar(10),
@date_of_birth datetime,
@customer_email_id varchar(50),
@customer_occuption varchar(50),
@customer_phone_number Bigint,
@nominee_name nchar(50),
@customer_id nvarchar(50),
@account_type nvarchar(50),
@account_number nvarchar(50),
@transfer_access_code nvarchar(50),
@account_balance Bigint,
@pin_code BigInt,
@nationality nvarchar(50),
@password nvarchar(50)
    
lblAmount.Text = HFamount .Value ;
int balamount = Convert.ToInt32(lblAmount.Text);
int Cpincode = Convert.ToInt32(txtpincode.Text);

long phone = Convert.ToInt64(txtphone.Text);
string cust_id = CUSTOMER_ID_GENERATOR();
string sqlquery = "INSERT INTO customer_details values(@customer_first_name,@customer_last_name,@customer_address,@gender,@date_of_birth,@customer_email_id,@customer_occuption,@customer_phone_number,@nominee_name,@customer_id,@account_type,@account_number,@transfer_access_code,@account_balance,@pin_code,@nationality,@password)";
string strconstring = ConfigurationManager.ConnectionStrings["ONLINE_BANKING2_ConnectionString"].ConnectionString;
SqlConnection mycon = new SqlConnection(strconstring);
mycon.Open();
SqlCommand  cmdRegister= new SqlCommand(sqlquery,mycon);
cmdRegister.Parameters.Add(new SqlParameter("@customer_first_name",txtcustname.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@customer_last_name",txtcustlastname.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@customer_address",txtAddress.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@gender", rbtngender.SelectedItem.Value.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@date_of_birth", txtDOB.Text));
cmdRegister.Parameters.Add(new SqlParameter("@customer_email_id", txtemail.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@customer_occuption",  txtcustoccupation.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@customer_phone_number",  phone));
cmdRegister.Parameters.Add(new SqlParameter("@nominee_name",  txtnominee.Text.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@customer_id",  cust_id));
cmdRegister.Parameters.Add(new SqlParameter("@account_type",  accType.SelectedItem.Value.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@account_number",  ACCOUNT_NUMBER_GENERATOR()));
cmdRegister.Parameters.Add(new SqlParameter("@transfer_access_code",Transfer_code()));
cmdRegister.Parameters.Add(new SqlParameter("@account_balance",  balamount));
cmdRegister.Parameters.Add(new SqlParameter("@pin_code",  Cpincode));
cmdRegister.Parameters.Add(new SqlParameter("@nationality", DropCountry.SelectedItem.Value.ToString()));
cmdRegister.Parameters.Add(new SqlParameter("@password",txtpasswd2.Text.ToString()));
cmdRegister.ExecuteNonQuery();
mycon.Close();

please help me

only views on reply

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很酷又爱笑 2024-10-02 19:47:25

一件事是尝试使用 int 作为 balmount 变量的数据类型而不是 long。然后请打印 balmount 变量的值并在您的问题中更新它。

问题可能不在于 balmount 中的任何非数字字符,因为在这种情况下,它会在 Comvert.toInt32() 行本身失败。

编辑:因为您使用的是“插入表值(...)”语法。您确定列顺序正确吗?为了避免任何混淆,您可以将插入语法更改为“插入表(col1,col2,... coln)值(@col1,@col2,...@coln)”。这会让您更好地了解要插入值的列。

One thing is try using int as datatype for balamount variable instead of long. Then please print the value of balamount variable and update it in your question.

The problem might not be with any non-numeric character in balamount, because in that case it would've failed at the line Comvert.toInt32() itself.

EDIT: Since you are using "Insert into table values(...)" syntax. Are you sure the column order is correct. To avoid any confusion, can you change your insert syntax to "Insert in table (col1, col2, ... coln) values (@col1, @col2,... @coln)". This would give you better idea as to which column you are inserting the values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文