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

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

问题描述

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.ToInt64(y);

obj.UPDATE_CUSTOMER(z,u);



}





CLASS LIBRARY

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

public IDataReader UPDATE_CUSTOMER(int customer_id,Double customer_mobile_no)

{

试试

{

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.Int64,c ustomer_mobile_no);

返回db.ExecuteReader(com);

}

catch(例外)

{< br $> b $ b抛出;

}

}



//更新客户数据

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; < br $>
}





带有存储程序的数据库表

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



CUSTOMER_MOBILE_NO BIGINT,





错误

-----------

SQLEXCEPTION没有处理



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

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.ToInt64(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.Int64, customer_mobile_no);
return db.ExecuteReader(com);
}
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 bigint to int.

推荐答案

我想说,这句话值得怀疑:



I would say, this statement is doubtfull:

Double u = Convert.ToInt64(y);





文档说明:将指定值转换为64位有符号整数

您尝试将该值转换为double - 为什么不这样:





The documentation says: Converts a specified value to a 64-bit signed integer.
You try to convert the value to double - why not like this:

Double u = Convert.ToDouble(y);


你很困惑 Int64 with Double Double 类型包含浮点值,并且会以您尝试的方式使用它时会出现各种问题。从发布的消息中,您似乎也试图将一个大整数存储到某个普通的整数中。请尝试显示出错的代码行。
You are confusing Int64 with Double in the above code. Double types hold floating point values and will cause you all sorts of problems using it the way you have tried. From the message posted, it would also appear that you are trying to store a big integer into a normal integer somewhere. Please try and show the line of code that gives the error.


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

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