By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

how to insert value programmaticaly (sqlDataAdapter)

P: n/a
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 insert a new record? from the c# or VB?
from the sql? (if i do "insert newid() ) it still give me an error message
:-(

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

Always i'm getting message: "Column "id" doesn't allow nulls. Do you want to
correct
the value?"

thank you


Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Ok the easiest is to make the id field a seed column of one, which
basically means that it will start at 0 and on every insert it will
automatically add 1 to it. I assume you are using MS SQL here. The
easiest is to go into enterprise manager and then go to design table
(right click on table and select) then click the column (id) then at
the bottom left are the properties, just set seed to true and the rest
will automatically happen, and save it.

Good luck

Nov 21 '05 #2

P: n/a
one more, then you would only need to create a stored procedure to
accept the value of name, because id is automatically assigned.

eg: INSERT INTO Dictionary (name) VALUES(@name)

Nov 21 '05 #3

P: n/a
Serdge,

Try to avoid if possible in VBNET (adonet) the autoincrement keys. It will
you give only trouble in future.

The most simple is to use, for every row that you have to insert, a New
Guid for the unique identifier

Have a look at this snippet.

http://www.windowsformsdatagridhelp....3-fee3733fcd6f

I hope this helps

Cor

"Serdge Kooleman" <Su***@web.de> schreef in bericht
news:OV**************@TK2MSFTNGP09.phx.gbl...
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 insert a new record? from the c# or VB?
from the sql? (if i do "insert newid() ) it still give me an error message
:-(

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

Always i'm getting message: "Column "id" doesn't allow nulls. Do you want
to
correct
the value?"

thank you

Nov 21 '05 #4

P: n/a
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 VB (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

"Rykie" <ry**********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Ok the easiest is to make the id field a seed column of one, which
basically means that it will start at 0 and on every insert it will
automatically add 1 to it. I assume you are using MS SQL here. The
easiest is to go into enterprise manager and then go to design table
(right click on table and select) then click the column (id) then at
the bottom left are the properties, just set seed to true and the rest
will automatically happen, and save it.

Good luck

Nov 21 '05 #5

P: n/a
Ok. Seems to me that i found the right answer. Answer is on C#, but hope it
is easy to convert it to VB.

I decided to use the event dsDictionary1.Tables[0].ColumnChanging
in form constructor:

InitializeComponent();

dsDictionary1.Tables[0].ColumnChanging += new
DataColumnChangeEventHandler(OnColumnChanging);
protected static void OnColumnChanging(object sender,
DataColumnChangeEventArgs args)

{

if (args.Column.ColumnName.ToString() == "DictionaryName")

if (args.Row["id"] == System.DBNull.Value)

{

args.Row["id"] = System.Guid.NewGuid();

}

}
thank you to everybody who participate in the discussion!
appreciate your help
serge

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 insert a new record? from the c# or VB?
from the sql? (if i do "insert newid() ) it still give me an error message
:-(

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

Always i'm getting message: "Column "id" doesn't allow nulls. Do you want
to
correct
the value?"

thank you

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.