views:

66

answers:

1

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

+1  A: 

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.

Sachin Shanbhag
yes i have done it but then also same error is occurring
@user404305 - Please see my edited answer
Sachin Shanbhag
hey i got it thankkkzz
@user404305 - So did this help to resolve your issue or is it still present?
Sachin Shanbhag
yes done bro i was not in sequence