Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error converting data type bigint to int.

See more: C#
C#
private void btnupdate_Click(object sender, EventArgs e)
{
 
int a = dataGridView1.CurrentRow.Index;
        string x = (dataGridView1.Rows[a].Cells[1].Value).ToString();
        string y = (dataGridView1.Rows[a].Cells[3].Value).ToString();
        int z = Convert.ToInt32(x);
        double u = Convert.ToDouble(y);
obj.UPDATE_CUSTOMER(z, u);
 
}
 

CLASS LIBRARY
----------------
public IDataReader UPDATE_CUSTOMER(int customer_id, Double customer_mobile_no)
{
try
         {
             DbCommand com = db.GetStoredProcCommand(USP_Update_Customer_Data);
             db.AddInParameter(com, USP_Update_Customer_Data_PARAM_1, DbType.Int32, customer_id);
             db.AddInParameter(com, USP_Update_Customer_Data_PARAM_2, DbType.Double, customer_mobile_no);
             return db.ExecuteReader(com);
         }
         catch (Exception)
         {
             throw;
}
catch (Exception)
{
throw;
}
}
 
// UPDATE CUSTOMER DATA
private const string USP_Update_Customer_Data = "USP_Update_Customer_Data";
private const string USP_Update_Customer_Data_PARAM_1 = "customer_mobile_no";
private const string USP_Update_Customer_Data_PARAM_2 = "customer_id";
}



DATABASE TABLE WITH STORED PROCEDURE
-----------------------------------------
 
CUSTOMER_MOBILE_NO BIGINT,


C#
ERROR
-----------
SQLEXCEPTION WAS UNHANDLED
 
Error converting data type float to int.

--------------------
Posted
v2
Comments
vinodkumarnie 25-Mar-13 4:52am    
which line you are getting error..?

CUSTOMER_MOBILE_NO BIGINT - oh no!!! A telephone number may be called a "number" in everydays speech, but it is not a number from an IT point of view: Numeric datatypes are for doing some kind of math (addition, multiplication, etc), but a mobile number is never used for such purposes. It is a string. Change your table definitions, stored procedures and code.
 
Share this answer
 
The only thing that raise from this code is that you have a mistake in the fields:

db.AddInParameter(com, USP_Update_Customer_Data_PARAM_1, DbType.Int32, customer_id);
private const string USP_Update_Customer_Data_PARAM_1 = "customer_mobile_no";

on the first row you use param1 for customer_id and in the second you use it for customer_mobile_no

same for param 2.

if this is not the answer you will need to add more data to the question. like the table and the stored procedure.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900