在插入sqlDataAdapter之前 [英] before insert sqlDataAdapter

查看:58
本文介绍了在插入sqlDataAdapter之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询:从字典中选择ID,名称


字段" id"是guid(所以不是空的,而不是身份)


我只显示名字在dataGrid中


当我插入新记录时如何设置新的id?

目前VS向导为我创建插入命令:


INSERT INTO Dictionary(id,name)VALUES(@ id,@ name);

SELECT id,name FROM Dictionary WHERE(id = @id)


它不起作用Columnid"不允许空值。你想纠正

的值吗?"


谢谢

i have a query: select id, name from Dictionary

field "id" is guid (so not null, and not identity)

i show only "name" in the dataGrid

how to set new id when i insert a new record?
currently VS wizard created insert command for me:

INSERT INTO Dictionary (id, name) VALUES (@id, @name );
SELECT id, name FROM Dictionary WHERE (id = @id)

it is not working "Column "id" doesn''t allow nulls. Do you want to correct
the value?"

thank you

推荐答案

将DataTable中的id列设置为值。喜欢Guid.NewGuid()。


或者在数据库中为列添加默认的''newid()''


" Serdge Kooleman <苏*** @ web.de>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
Set the ''id'' column in your DataTable to a value. Like Guid.NewGuid().

Or give the column a default of ''newid()'' in the database

"Serdge Kooleman" <Su***@web.de> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
我有查询:从字典中选择id,名称

字段" id"是guid(所以不是空的,而不是身份)

我只显示名字在dataGrid中

当我插入新记录时如何设置新的id?

目前VS向导为我创建了插入命令:

INSERT INTO字典(id,name)VALUES(@ id,@ name);
SELECT id,name FROM Dictionary WHERE(id = @id)

它不起作用Columnid id ;不允许空值。你想纠正这个价值吗?

谢谢你
i have a query: select id, name from Dictionary

field "id" is guid (so not null, and not identity)

i show only "name" in the dataGrid

how to set new id when i insert a new record?
currently VS wizard created insert command for me:

INSERT INTO Dictionary (id, name) VALUES (@id, @name );
SELECT id, name FROM Dictionary WHERE (id = @id)

it is not working "Column "id" doesn''t allow nulls. Do you want to correct
the value?"

thank you



自动生成的更新/插入查询是基于SELECT查询的参数

。由于您同时选择了ID和名称,因此生成的查询中会出现相同的

参数。但是,如果ID是主要的

键(并且您将其配置为在数据库中自动增加),则不需要

将其作为一部分提供插入查询。当您插入新记录时,将自动生成一个新ID



-

Kai Brinkmann [微软]


请不要直接向此别名发送电子邮件。此别名仅适用于

新闻组。

此帖子按原样提供。没有保证,也没有赋予任何权利。


" Serdge Kooleman" <苏*** @ web.de>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
Automatically generated updated/insert queries are based on the parameters
of the SELECT query. Since you are selecting both ID and name, the same
parameters end up in the generated queries. However, if ID is the primary
key (and you configured it to auto-increment in your DB), you don''t need to
provide it as part of the insert query. A new ID will be generated
automatically when you insert a new record.
--
Kai Brinkmann [Microsoft]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

"Serdge Kooleman" <Su***@web.de> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
我有查询:从字典中选择id,名称

字段" id"是guid(所以不是空的,而不是身份)

我只显示名字在dataGrid中

当我插入新记录时如何设置新的id?

目前VS向导为我创建了插入命令:

INSERT INTO字典(id,name)VALUES(@ id,@ name);
SELECT id,name FROM Dictionary WHERE(id = @id)

它不起作用Columnid id ;不允许空值。你想纠正这个价值吗?

谢谢你
i have a query: select id, name from Dictionary

field "id" is guid (so not null, and not identity)

i show only "name" in the dataGrid

how to set new id when i insert a new record?
currently VS wizard created insert command for me:

INSERT INTO Dictionary (id, name) VALUES (@id, @name );
SELECT id, name FROM Dictionary WHERE (id = @id)

it is not working "Column "id" doesn''t allow nulls. Do you want to correct
the value?"

thank you



我提到我的身份不是自动递增。谁使用它?!

i有基于guid的id。

如何在我的情况下更新id?
i mentioned that my id is not auto-increment. who use it?!
i have guid-based id.
how to update id in my case?
自动生成更新/ insert查询基于SELECT查询的参数
。由于您同时选择了ID和名称,因此生成的查询中会出现相同的参数。但是,如果ID是主键(并且您将其配置为在数据库中自动递增),则不需要
将其作为插入查询的一部分提供。当您插入新记录时,将自动生成新ID。
-
Kai Brinkmann [微软]
Automatically generated updated/insert queries are based on the parameters
of the SELECT query. Since you are selecting both ID and name, the same
parameters end up in the generated queries. However, if ID is the primary
key (and you configured it to auto-increment in your DB), you don''t need
to provide it as part of the insert query. A new ID will be generated
automatically when you insert a new record.
--
Kai Brinkmann [Microsoft]



这篇关于在插入sqlDataAdapter之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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