473,785 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to insert value programmaticaly (sqlDataAdapter )

i have a query: select id, name from Dictionary
field "id" is uniqueidentifie r (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
5 5413
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
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
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******** ******@TK2MSFTN GP09.phx.gbl...
i have a query: select id, name from Dictionary
field "id" is uniqueidentifie r (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
1. i'm not looking for the easiest way, sorry.
2. i use WinForms, not Web!
3. id have "uniqueidentife r" 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**********@g mail.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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
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.T ables[0].ColumnChanging
in form constructor:

InitializeCompo nent();

dsDictionary1.T ables[0].ColumnChanging += new
DataColumnChang eEventHandler(O nColumnChanging );
protected static void OnColumnChangin g(object sender,
DataColumnChang eEventArgs args)

{

if (args.Column.Co lumnName.ToStri ng() == "DictionaryName ")

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

{

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

}

}
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 uniqueidentifie r (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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2567
by: Big E | last post by:
I'm using ASP.Net and SQL Server 2000. I'm trying to insert or update records from a multiselect listbox. How can I get the contents of the listbox if there is more than one selected and update that into the database. But most important how do I update or insert those records. Any articles or ideas would be appreciated. Thanks. Big e
6
2083
by: Lelle | last post by:
Hello ! how can i insert text containg code examples from a textbox into a database using SQL insert statment. i have no problem to just add text that dont contains code and script examples or the illegal chars for the insert command is it possible to encasulate the text/string so the server doesnt reads the string as a command?
0
1526
by: Eustice Scrubb | last post by:
In line coding problem. Here's my code: <script language="VB" runat="server"> Dim myConnection As SqlConnection Sub Page_Load(Src As Object, e As EventArgs) ' Create a connection to the SQL Server myConnection = New SqlConnection("Data Source=SERVER;" _ & "Initial Catalog=database;User Id=user;Password=password;")
2
1529
by: krajah | last post by:
Need Help Here....... I'm using visual C#: How to insert the value that user have entered combobox and click button.The value will sent into database.This is in form1. In form2,if click button it will display in listbox.There also got another button to to delete the value according the index have chose using cursour. I'm using sql server 2005,the were connection problem.How to know the server name for my computer. Below is the coding I...
1
1904
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', table; column does not allow nulls. INSERT fails. (ID IS MY KEY) I can update & delete fine, but when I try to insert, I cannot figure out how to get the primary key inserted. I'm new @ this & I think I've confused myself.... THANK YOU Dim...
1
3713
by: RB | last post by:
Hi All, I'm trying to use more data-adapters/data-sets in a project, because they are so awesome! Anyhoo, I want to use them with Stored Procedures, rather than raw SQL text. The hard part of working with SPs is passing the new values to the insert, update and delete stored procedures. I've figured out one way to do it, but was wondering if anyone else had any better ideas, as my way, although it works fine, means writing quite a lot...
3
1421
by: RN1 | last post by:
This is how I am trying to insert a new record in a database table & then display all the records (including the newly inserted record) in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Dim dSet As DataSet Dim dTable As DataTable Dim sqlCmd As SqlCommand Dim sqlConn As SqlConnection
7
5794
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 result as no row is effected ...Please help me guys using System;
3
3789
by: buterfly0707 | last post by:
hi evryone.. i want to get the text box value to list box . And also i want this textbox value enter into the dabasex table called Area and @ th esame time insert this value to List box. here is the code wich i have use. SqlConnection conn = new SqlConnection(ConnectionString); String S = "Insert into Area values ('" + textBox1.Text.ToString().Trim() + "')"; SqlCommand command = new SqlCommand(S); ...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10087
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5380
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.