如何解决将数据类型varchar转换为bigint的错误 [英] how to solve Error converting data type varchar to bigint
本文介绍了如何解决将数据类型varchar转换为bigint的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string strItem = GridView1.Rows[e.RowIndex].FindControl("txtItem").ToString();
string strInvoiceNoFrm = GridView1.Rows[e.RowIndex].FindControl("txtInvoiceNoFrm").ToString();
string strInvoiceNoTo = GridView1.Rows[e.RowIndex].FindControl("txtInvoiceNoTo").ToString();
string strDetails = GridView1.Rows[e.RowIndex].FindControl("txtDetails").ToString();
string strRemark = GridView1.Rows[e.RowIndex].FindControl("txtRemark").ToString();
string strSrNo = GridView1.Rows[e.RowIndex].FindControl("lblSrNo").ToString();
try
{
//Prepare the Update Command of the DataSource control
string strSQL = "";
strSQL = "UPDATE InvoiceDetails set Item = '" + strItem + "'" +
",InvoiceNoFrm = '" + strInvoiceNoFrm + "'" +
",InvoiceNoTo = '" + strInvoiceNoTo + "'" +
",Details = '" + strDetails + "'" +
",Remark = '" + strRemark + "'" +
" WHERE SrNo = '" + strSrNo + "'";
SqlDataSource2.UpdateCommand = strSQL;
SqlDataSource2.Update();
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Enquiry updated successfully');</script>");
}
catch { }
推荐答案
您好,
首先,永远不要以这种方式使用SQL代码,这将为SQL注入打开一个大漏洞( http://en.wikipedia .org/wiki/SQL_injection [ ^ ]).
无论如何,我认为您想将SQL varchar转换为SQL bigint,因为SQL查询返回它无法从头开始将其转换,对吗?
因此,如果要将SQL中的varchar转换为bigint,可以使用SQL函数convert()
( http://msdn.microsoft.com/en-us/library/ms187928.aspx [ ^ ]):
Hi,
First of all, never ever use SQL code this way, this will open up a big hole for SQL Injections (http://en.wikipedia.org/wiki/SQL_injection[^]).
Anyway, I think you want to convert a SQL varchar to a SQL bigint because the SQL query returns that it cannot convert it from scratch, right?
So if you want to convert a varchar to a bigint in SQL, you could use the SQL functionconvert()
(http://msdn.microsoft.com/en-us/library/ms187928.aspx[^]):
CONVERT(bigint, ''123456789'')
或作为SQL Management Studio的单个查询可执行文件:
or as a single query executable by the SQL management studio:
SELECT CONVERT(bigint, ''123456789'')
希望对您有所帮助.
致以诚挚的问候,祝您编程愉快,
停止
I hope this helps.
Best regards and happy coding,
Stops
这篇关于如何解决将数据类型varchar转换为bigint的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文