Hello,
I have an autoincrement field and I'm not sure how to use a parameter
with it to insert data:
this.sqlCommand 1.CommandText = "INSERT INTO SickAndTired (String_ID,
Input_string) VALUES (@Parameter1,@P arameter2)";
this.sqlCommand 1.Connection = this.sqlConnect ion1;
this.sqlCommand 1.Parameters.Ad d(new
System.Data.Sql Client.SqlParam eter("@Paramete r1",
System.Data.Sql DbType.UniqueId entifier, 0, "String_ID" ));
this.sqlCommand 1.Parameters.Ad d(new
System.Data.Sql Client.SqlParam eter("@Paramete r2",
System.Data.Sql DbType.NVarChar , 0, "Input_String") );
this.sqlConnect ion1.Open();
string TB1 = this.textBox1.T ext;
sqlCommand1.Par ameters["@Parameter 1"].Value= (What do I put
here??????????? ????????)
sqlCommand1.Par ameters["@Parameter 2"].Value=TB1;
sqlCommand1.Exe cuteNonQuery();
this.sqlConnect ion1.Close();
Thanks
Mike 4 7212
Mike,
For something like this, you aren't going to get it through a parameter
in a select. Rather, you have to issue a select on the same open connection
on the @@IDENTITY value, which will return the last inserted identity value
for that session.
You have to be careful, since the identity can be changed by triggers
(if you insert into other tables with auto-generated identity fields then
that value will be returned).
Generally, this is a good argument for managing the id generation
yourself. Personally, I prefer to use GUIDs, since I can generate them
before the operation starts, and know exactly what my id will be (before and
after).
If you want to get this in a parameter, then create a stored procedure
which will select the @@IDENTITY value and return that in a parameter.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Mike" <am******@veriz on.net> wrote in message
news:N6_Re.121$ tx.8@trndny02.. . Hello,
I have an autoincrement field and I'm not sure how to use a parameter with it to insert data:
this.sqlCommand 1.CommandText = "INSERT INTO SickAndTired (String_ID, Input_string) VALUES (@Parameter1,@P arameter2)";
this.sqlCommand 1.Connection = this.sqlConnect ion1;
this.sqlCommand 1.Parameters.Ad d(new System.Data.Sql Client.SqlParam eter("@Paramete r1", System.Data.Sql DbType.UniqueId entifier, 0, "String_ID" ));
this.sqlCommand 1.Parameters.Ad d(new System.Data.Sql Client.SqlParam eter("@Paramete r2", System.Data.Sql DbType.NVarChar , 0, "Input_String") );
this.sqlConnect ion1.Open();
string TB1 = this.textBox1.T ext; sqlCommand1.Par ameters["@Parameter 1"].Value= (What do I put here??????????? ????????)
sqlCommand1.Par ameters["@Parameter 2"].Value=TB1; sqlCommand1.Exe cuteNonQuery();
this.sqlConnect ion1.Close(); Thanks Mike
scope_identity( ) is probably safer to use. @@identity can potentially
produce very hard to find bugs in your app.
"Mike" wrote: Hello,
I have an autoincrement field and I'm not sure how to use a parameter with it to insert data:
this.sqlCommand 1.CommandText = "INSERT INTO SickAndTired (String_ID, Input_string) VALUES (@Parameter1,@P arameter2)";
this.sqlCommand 1.Connection = this.sqlConnect ion1;
this.sqlCommand 1.Parameters.Ad d(new System.Data.Sql Client.SqlParam eter("@Paramete r1", System.Data.Sql DbType.UniqueId entifier, 0, "String_ID" ));
this.sqlCommand 1.Parameters.Ad d(new System.Data.Sql Client.SqlParam eter("@Paramete r2", System.Data.Sql DbType.NVarChar , 0, "Input_String") );
this.sqlConnect ion1.Open();
string TB1 = this.textBox1.T ext; sqlCommand1.Par ameters["@Parameter 1"].Value= (What do I put here??????????? ????????)
sqlCommand1.Par ameters["@Parameter 2"].Value=TB1; sqlCommand1.Exe cuteNonQuery();
this.sqlConnect ion1.Close(); Thanks Mike
All I did was left that parameter out and it incremented by 1.Should I have
made it more complicated?
"carion1" <ca*****@discus sions.microsoft .com> wrote in message
news:06******** *************** ***********@mic rosoft.com... scope_identity( ) is probably safer to use. @@identity can potentially produce very hard to find bugs in your app.
"Mike" wrote:
Hello,
I have an autoincrement field and I'm not sure how to use a parameter with it to insert data:
this.sqlCommand 1.CommandText = "INSERT INTO SickAndTired (String_ID, Input_string) VALUES (@Parameter1,@P arameter2)";
this.sqlCommand 1.Connection = this.sqlConnect ion1;
this.sqlCommand 1.Parameters.Ad d(new System.Data.Sql Client.SqlParam eter("@Paramete r1", System.Data.Sql DbType.UniqueId entifier, 0, "String_ID" ));
this.sqlCommand 1.Parameters.Ad d(new System.Data.Sql Client.SqlParam eter("@Paramete r2", System.Data.Sql DbType.NVarChar , 0, "Input_String") );
this.sqlConnect ion1.Open();
string TB1 = this.textBox1.T ext; sqlCommand1.Par ameters["@Parameter 1"].Value= (What do I put here??????????? ????????)
sqlCommand1.Par ameters["@Parameter 2"].Value=TB1; sqlCommand1.Exe cuteNonQuery();
this.sqlConnect ion1.Close(); Thanks Mike
Were you trying to insert a value into the identity column? If you need to
do that for what ever reason you can use set identity_insert <table name> on.
You don't have to increment the identity column yourself unless your app
depends on the identity field not having gaps from deleted records.
"Mike" wrote: All I did was left that parameter out and it incremented by 1.Should I have made it more complicated?
"carion1" <ca*****@discus sions.microsoft .com> wrote in message news:06******** *************** ***********@mic rosoft.com... scope_identity( ) is probably safer to use. @@identity can potentially produce very hard to find bugs in your app.
"Mike" wrote:
Hello,
I have an autoincrement field and I'm not sure how to use a parameter with it to insert data:
this.sqlCommand 1.CommandText = "INSERT INTO SickAndTired (String_ID, Input_string) VALUES (@Parameter1,@P arameter2)";
this.sqlCommand 1.Connection = this.sqlConnect ion1;
this.sqlCommand 1.Parameters.Ad d(new System.Data.Sql Client.SqlParam eter("@Paramete r1", System.Data.Sql DbType.UniqueId entifier, 0, "String_ID" ));
this.sqlCommand 1.Parameters.Ad d(new System.Data.Sql Client.SqlParam eter("@Paramete r2", System.Data.Sql DbType.NVarChar , 0, "Input_String") );
this.sqlConnect ion1.Open();
string TB1 = this.textBox1.T ext; sqlCommand1.Par ameters["@Parameter 1"].Value= (What do I put here??????????? ????????)
sqlCommand1.Par ameters["@Parameter 2"].Value=TB1; sqlCommand1.Exe cuteNonQuery();
this.sqlConnect ion1.Close(); Thanks Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bruce Stockwell |
last post by:
the setup:
Webservice/WinClient application/SQL server.
VS.Net (visual basic) winform wizard creates a simple form
with load cancel cancelall and datagrid bound to a simple
Dataset with one Datatable. No coding by programer, All
wizardry. User starts app, opens form, adds (4) records
and clicks update.
|
by: Tom |
last post by:
I am trying to store information into a table that has an auto
increment field. There is currently no data in the table. Using the
code below I cannot insert data into the table. I get an error telling
me that "Number of query values and destination fields are not the
same."
If I add a value for the auto increment field to the SQL String the
data is entered into the table with no problems but obviously the auto
increment field now...
|
by: Pauloviè Michal |
last post by:
hi all,
I have problem with SERIAL field type (or sequence functionality).
I have table with three columns - ID, IDS, NAME.
I want auto-increment IDS grouped by ID.
Example:
1, 1, Ferdo
1, 2, John
2, 1, Martin
1, 3, Elvira
|
by: vul |
last post by:
In VB6 there is Auto Increment check box in Project Properties, which allow
you have a new version every time you compile the project.
Is there any easy way to have this feature in VB 2005?
Some of my blocks of code check and compare versions of EXE and DLLs located
on the local workstation and the server. So it's very important for me to
have an incremented number in case the project was rebuilt. It can be done
manually, of course, but I...
|
by: john |
last post by:
Is it true that if I split my access database in backend and frontend and I
implement custom auto increment for the ID fields, that my database is ready
to be used in a multi-user environment? I found a zillion messages about
auto increment and read some of them but it's confusing. Can someone point
me to a simple custom auto increment example that I can download?
Thank you,
john
| |
by: rhepsi |
last post by:
hii all,
i have created a database with a table with number of fields....in msaccess
ive set primary key as SNo: and its datatype as auto number...
How to set the auto increment ????
For ex:
|
by: chumlyumly |
last post by:
Hello scripters -
OS: Mac OSX
Language: PHP w/ MySQL database
I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The tables are all linked with the field 'member_id', which is an auto-increment field in the parent table ('members').
I've been able to input multiple records into the other three tables 'specialty_groups', 'committee_interest' and 'committee_member'...
|
by: jimilives |
last post by:
I forgot to turn on auto increment when I reinstalled this database and now I have a bunch of NULL values in my ID field for last few hundred inserts, how can I update this table to replace the NULLS with a new ID value where the ID is an auto increment with out losing the ID values of old records, basically i want to do this:
UPDATE ID SET id = 'NEW AUTO #' where ID = 'NULL'
I hope this makes sense, I am not bound to having the numbers...
|
by: BobLewiston |
last post by:
Using Visual C# 2008 Express and SQL Server 2008 Express, I would like to insert new records into database "AdventureWorks", table "Person.Contact".
To my surprise, this table's int-value identity column "ContactID" does not appear to be auto-increment. I don't know how to confirm for sure that this is so. (I have installed SQL Server Management Studio, if that helps.)
How can I confirm this, and how can I make ContactID auto-increment?
...
|
by: paulyXvpf |
last post by:
Hello, all...
Just finished a handy tutorial that has helped me understand how to auto increment and post to a web page... but its only a Web User Control passing values from VB.NET method statements... I really need the increment and post from a SQL Server 2000 database
See Example:
http://sql-paul.com/lesson27_VB/Default.aspx
See Flowchart/Code Behind (I created it in Visio)
http://sql-paul.com/lesson27_VB/Control_State_Flowchart.htm
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |