473,467 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

before insert sqlDataAdapter

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
Nov 17 '05 #1
10 2934
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...
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

Nov 17 '05 #2
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...
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

Nov 17 '05 #3
i mentioned that my id is not auto-increment. who use it?!
i have guid-based id.
how to update id in my case?
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]

Nov 17 '05 #4
> Set the 'id' column in your DataTable to a value. Like Guid.NewGuid().
how to update it? (i have DataSet)
do we have an event like "before insert" ?

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

i tried to do it. the same result.
Nov 17 '05 #5
If the ID is a required value, you will have to figure out a way to create a
new ID before executing the INSERT query. Look at Marina's suggestion.
--
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:OZ**************@TK2MSFTNGP14.phx.gbl...
i mentioned that my id is not auto-increment. who use it?!
i have guid-based id.
how to update id in my case?
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]


Nov 17 '05 #6
Kai,

seems to me that u do not understand what i need.

i do not want to use newid() function in sql.
i want to generate new guid in C# ( System.Guid.NewGuid() )
could you give a code example? what event should i use?

where i should write: parameter['ID'] = 'value' ?
where ?
what event or something like this?

thank you

If the ID is a required value, you will have to figure out a way to create
a new ID before executing the INSERT query. Look at Marina's suggestion.


i know how to generate new ID.
in what place shoud i add this value to parameter?

thank you
Nov 17 '05 #7
forget to say: i use WinForms
Nov 17 '05 #8
At some point you are adding a row to this datatable. So where ever you add
the row, that's where you set the column value.

"Serdge Kooleman" <Su***@web.de> wrote in message
news:ex**************@TK2MSFTNGP14.phx.gbl...
Set the 'id' column in your DataTable to a value. Like Guid.NewGuid().

how to update it? (i have DataSet)
do we have an event like "before insert" ?

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

i tried to do it. the same result.

Nov 17 '05 #9
> At some point you are adding a row to this datatable. So where ever you
add the row, that's where you set the column value.


Marina, i add row in DataGrid (winforms).
And i exactly need an advise: where to put code
parameter[id] = "something"

where? i do not see any places for that.... no any "before update event"
Nov 17 '05 #10
1. i'm not looking for the easiest way, sorry.
2. i use WinForms, not Web!
3. id have "uniqueidentifer" type. so i cannot use autoincrement for it ;-)
4. i want to update this field from C# without using additional SQL
statements like newid()

so i just want to repeat stuff that i did in Delphi a lot of times.
where i can put procedure like this:

onbeforeupdate
parameter['id'] = "{6F9619FF-8B86-D011-B42D-00C04FC92455}"
endproc

again, i'm using DataGrid with DataSet and sqlDataAdapter

tnank you
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

Nov 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: adove | last post by:
I am having problems with the following code. I am trying to update my db table Categories in Northwind. I have borrowed this code from www.dotnetjohn.com/articles/articleid27.aspx Although it...
5
by: randy | last post by:
Hello all, I have a DataTable which I am building column by column and adding rows after each new column. The DataTable columns match the columns in my database table. I'm building the...
1
by: Pesko S | last post by:
Hi, Could anybody just point me in a direction where I can find information on how the heck I can update a database with relational data from an XML file. I use stored procedures to insert...
1
by: Serdge Kooleman | last post by:
i have a query: select id, name from Dictionary field "id" is uniqueidentifier (primary key id is not null, and not identity !) i show only "name" in the dataGrid how to set up new id when i...
2
by: Serdge Kooleman | last post by:
i have a query: select id, name from Dictionary field "id" is uniqueidentifier (primary key id is not null, and not identity !) i show only "name" in the dataGrid how to set up new id when i...
3
by: Ed | last post by:
Hi, I want to load data to a table in Sql Server from a dataset table in my vb.net app using a dataAdapter. I know how to do this as follows (my question is to see if I can reduce the amount...
0
by: mcasey0827 | last post by:
I'm writing a little app to get data from a CSV file generated everyday by a vendor and insert it into a Table in our SQL Server database. I can get the data fine, and I can easily merge it with...
1
by: niccolem | last post by:
HI: Can someone tell me HOW to insert a automatic number after my user inserts new data from text boxes into the dataset. I keep getting this error: Cannot insert the value NULL into column 'id',...
7
by: anu b | last post by:
Hi I need to use Clr trigger for insert command My code is as below I am using SQL server 2005 and VS 2008.... but after running this code i didnt get the result as i expexted it shows the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.