简体   繁体   English

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

[英]error in converting datatype nvarchar to bigint

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 仅回复意见

One thing is try using int as datatype for balamount variable instead of long. 一件事是尝试使用int作为balamount变量的数据类型,而不是long。 Then please print the value of balamount variable and update it in your question. 然后,请打印balamount变量的值,并在问题中对其进行更新。

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. 问题可能不在于balamount中的任何非数字字符,因为在那种情况下,它在Comvert.toInt32()本身行上将失败。

EDIT: Since you are using " Insert into table values(...)" syntax. 编辑:由于您正在使用“ Insert into table values(...)"语法。 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)". 为避免混淆,可以将插入语法更改为“ 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. 这样可以使您更好地了解要插入值的列。

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

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