更新中的GUID问题 [英] guid problem in update

查看:91
本文介绍了更新中的GUID问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个guid abcde,我在表guid中有一个ID,我想进行更新,但不起作用.


string cmd1 = "UPDATE Publisher SET checkid=''"+ CheckBoxList1.SelectedValue.ToString() + "'' WHERE idi=" + abcde + "";


abcde值为1996c33b-786c-4acf-87c1-14c9c9fbc879


错误是:"c33b"附近的语法不正确.


请帮忙.

Hi i have a guid abcde and i have id in table guid i want to make an update but doesn works.


string cmd1 = "UPDATE Publisher SET checkid=''"+ CheckBoxList1.SelectedValue.ToString() + "'' WHERE idi=" + abcde + "";


abcde value is 1996c33b-786c-4acf-87c1-14c9c9fbc879


The error is: Incorrect syntax near ''c33b''.


Please help.

推荐答案

Prevas,
为什么不使用GUID作为

Hi Prevas,
Why dont you use GUID as

GUID.ToString().Substring(0,7)



或者您也可以使用



or you can also use

GUID.ToString().Replcae("-","")

;


这样,您在查询期间将不会获得任何-",因此可以避免此类错误.



Anurag

;


This way you will not get any "-" during queries and hence can avoid such type of errors.



Anurag


首先,永远不要使用来自asp.net的未经验证的输入进行数据库查询.其次,不要使用字符串连接.您应该使用参数化查询.
First, you should never use unvalidated input from asp.net for a database query. Second, don''t use string concatenation. You should use parameterized queries.


WHERE idi=" + abcde + "";

确保abcde的类型为GUID.
WHERE idi=" + abcde + "";

Make sure abcde is of type GUID.


这篇关于更新中的GUID问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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