将数据类型 nvarchar 转换为 bigint 时出错
此代码给我错误:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一件事是尝试使用 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.