将数据类型float转换为int时出错。 [英] Error converting data type float to int.

查看:198
本文介绍了将数据类型float转换为int时出错。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



查看更多: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 ]。值)的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 (例外)
{
throw ;
}
catch (例外)
{
throw ;
}
}

// 更新客户数据
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;
}







带有存储过程的数据库表
-----------------------------------------

CUSTOMER_MOBILE_NO BIGINT,





 ERROR 
--------- -
SQLEXCEPTION WH UNHANDLED

将数据类型 float 转换为 int

--------------------

解决方案

< blockquote> CUSTOMER_MOBILE_NO BIGINT - 哦不!在日常用语中,电话号码可能被称为号码,但从IT角度来看,它不是一个数字:数字数据类型用于进行某种数学运算(加法,乘法等),但移动数字从不用于此目的。这是一个字符串。更改您的表定义,存储过程和代码。


此代码中唯一引起的是您在字段中出错:



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;



在第一行使用param1为customer_id,第二行使用它为customer_mobile_no



与param 2相同。



如果这不是您需要在问题中添加更多数据的答案。像表和存储过程一样。


Error converting data type bigint to int.

See more: 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,



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

--------------------

解决方案

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.


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.


这篇关于将数据类型float转换为int时出错。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆