如何在asp中使用sql insert查询中的newid() [英] how to use newid() in sql insert query with asp

查看:328
本文介绍了如何在asp中使用sql insert查询中的newid()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在内联插入查询中我可以写

插入表id = newid()......



参数化查询在c#



插入表(name,id)值(@ name,@ id)......

sqlcommand.parameter .addwithvalue(@ name,souvik);

sqlcommand.parameter.addwithvalue(@ id,?);



如何使用newid()?

解决方案

NEWID 是一个函数,你不能将它用作参数(你应该在insert语句中明确地调用它)。请参阅文档:NEWID(Transact-SQL) [ ^ ]。


I建议在ID列的默认约束中使用此函数



例如:



 create table abc 


name varchar(20)not null,
ID varchar(16)default(newID())



现在写下你的插入语句如下:

插入ABC(名称)值('person1') 





请注意,您可以根据需要使用各种数据类型而不是varchar(16)。


< blockquote> insert into table(name,id)values(@ name,newid())...

sqlcommand.parameter.addwithvalue(@ name,souvik);

in inline insert query I can write
"insert into table id=newid()..."

In parameterized query in c#

"Insert into table (name,id) values (@name,@id)..."
sqlcommand.parameter.addwithvalue("@name","souvik");
sqlcommand.parameter.addwithvalue("@id",?);

how to use newid()?

解决方案

NEWID is a function, you can't use it as a parameter (you should call it explicitely in the insert statement). Please see the documentation: "NEWID (Transact-SQL)"[^].


I would suggest to use this function in default constraint for ID Columns

for Eg:

create table abc
(

name varchar(20) not null,
ID varchar (16) default(newID())

)


now write your insert statement as below:

Insert into ABC(name) values ('person1')



Note that you can use various datatype instead of varchar(16) as per your requirement.


insert into table (name,id) values (@name,newid())..."
sqlcommand.parameter.addwithvalue("@name","souvik");


这篇关于如何在asp中使用sql insert查询中的newid()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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