Tracking Forums, Newsgroups, Maling Lists
Home Submit Tracker Forums
  Advanced Search


C# - Inserting Row Into Table With Auto Increment Value?

I got a table PartsMedia where I can insert all the images related to a product. The table has the columns :

PartsMediaID , auto-increment

I want to insert a complete row with automatic increment and the PartsNo should be the same as the PartsNo from the PartsMaster table.

The medialink should be the PartsNo + '-2.jpg'
The mediadescription is for example 'image2'
The CatalogCode should be 'catalog'
and the sorting code should be '0'

From The partsMaster table I Just need the PartNo So I can add this to the PartMedia Table. The PartNo is the foreign key in the PartMedia table.

The following I got so far but no luck

insert into dbo.PartsMedia (PartNo,MediaLink,MediaDescription,CatalogCode, SortCode)
values (dbo.PartsMaster.PartNo, PartsMaster.PartNo+'-2.jpg','image2', 'catalog','0')

View 3 Replies (Posted: Mar 23 at 9:15)

Sponsored Links:

Related Forum Messages For ASP.NET category:
ADO.NET :: Get Auto Increment Field After Inserting?
I'm adding a couble of fields to database but i need the primary key of the master table to add it to sub table.

The database contains 2 tables :

Question Table :questionID(primary key and identity) , questionInText

Answer table : answerID , answer1,answer2 , questionID

code used to insert to db :


questionID is auto increment.

The question is : How i get questionID after adding to database without using sql statment ?

Posted: Dec 06, 2010 10:00 AM

View 1 Replies!   View Related
How To Auto Increment Field Value After Inserting To Database
i'm working on my first project on using c#.

I'm adding a couble of fields to database but i need the primary key of the master table to add it to sub table.

The database contains 2 tables :

Question Table :questionID(primary key and identity) , questionInText

Answer table : answerID , answer1,answer2 , questionID

code used to insert to db :


Posted: Dec 6 10

View 1 Replies!   View Related
DataSource Controls :: Get Next Auto Increment Value From Table?
i have a question, suppose i have a table 'tblImage' which have 3 rows of data and my auto increment is not +1.

imageId imageName
1 a.gif
2 b.gif
4 c.gif

i want to query '2' using LINQ C# to the table in MS SQL and show the record which i have done easily BUT now i want to get the next auto incremented value to make Next button on the sane web form, which is in this case is '4' and i also want the previous imageId as well.

Posted: Apr 28, 2010 08:28 PM

View 5 Replies!   View Related
SQL Server :: How To Auto Increment Alphanumeric Primary Key In Database Table
auto increment alphanumeric primary key(eg :ABC001) in sql server 2005 database table.

Posted: Sep 30, 2010 02:56 PM

View 2 Replies!   View Related
DataSource Controls :: Obtain Inserted Table Row Identity With An Auto Increment Key
I am using LINQ to store and retrieve data from tables with a clustered index key. However, I also need to know how to obtain an inserted table row identity with an auto-increment Primary key. The "Go To Definition" feature for my data context of dataClassesDataContext provides the following information:

public partial class DataClassesDataContext : System.Data.Linq.DataContext

I am asking for the C# code that is needed in a button click event handler that will insert a row of data in a table named "Fields".It only consists of an auto-incrementing primary key column (FieldID), a string column (Phrase) and a null defaulted variable column.

Posted: Feb 18, 2010 02:50 AM

View 3 Replies!   View Related
How To Auto Populate / Auto Increment In VB
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:


See Flowchart/Code Behind (I created it in Visio)


Posted: Jun 3 09

View 3 Replies!   View Related
Auto Increment The Record Number?
i am using one text box in New registration page. when ever user clicks on New registration button, The text box of record number should be auto incremented.

Posted: Apr 29, 2010 04:35 AM

View 12 Replies!   View Related
Auto Increment Feature In Database?
I use SQL Server and when I create a new table I make a specific field an auto increment
primary key. The problem is some people told me making the field an auto increment for the primary key means when deleting any record (they don't care about the auto increment field number) the field increases so at some point - if the type of my field is integer for example - the range of integer will be consumed totally and i will be in trouble.

So they tell me not to use this feature any more.The best solution is making this through the code by getting the max of my primary key then if the value does not exist the max will be 1 other wise max + 1.Any suggestions about this problem? Can I use the auto increment feature?I want also to know the cases which are not preferable to use auto increment ..and the alternatives...note :: this question is general not specific to any DBMS , i wanna to know is this true also for DBMSs like

Posted: Nov 2 10 at 7:16

View 6 Replies!   View Related
Web Forms :: Auto Increment Of Primary Key Which Is Varchar?
i was given a form in which empid is varchar and i m supposed to auto increment it using a function and calling it ....i have never done this. plz help me out the way .

Posted: Sep 21, 2010 05:09 PM

View 9 Replies!   View Related
How To Assign Auto Increment To Primary Key In VWD 2008
I am new to vwd 2008. I cant find the control to assign auto increment to primary key..

Posted: Dec 19, 2008 03:23 PM

View 4 Replies!   View Related
How Do Auto Increment Build/version Number
I have read that you can simply change the assembly version number to 1.0.* and it will auto increment.

Then I read that doing so will cause all kinds of registry issues...


He says to download a file to do this for you...

If anyone is currently doing this with no issues I would like your advice.

If you have had issues doing this I would like your warnings.

Posted: Jul 24, 2009 02:29 PM

View 1 Replies!   View Related
DataSource Controls :: How To Add A Column For Auto-increment
i am a beginner in using ASP.NET. I have this problem. Whenever i select the advanced options in configuring the sqldatasource, the Advanced SQL Generation Options are all greyed out/disabled. Now, i found out that the cause of this is because the table that i am trying to access doesnt have a primary key. the scenario is that the table already has data.

My question is, how do i put a column in, that can serve as the primary key for the table? I want to do this only in and not through using SSMS.

Posted: Dec 10, 2009 06:24 AM

View 3 Replies!   View Related
SQL Server :: How To Add A Fixed Value To Auto-increment Primary Key
If its posible I want to create a table with a primary key with auto-increment and a fixed value to differentiate the table from others tables


table 1 | table 2
a1 |b1
a2 |b2
a3 |b3

Posted: Jan 01, 2011 08:58 PM

View 6 Replies!   View Related
SQL Server :: Auto Increment Column In SQL View
show me what is the syntax to add an increment column to Select Query? There will be additional column which goes 1,2,3 ... n.

Posted: Oct 23, 2010 04:46 PM

View 3 Replies!   View Related
SQL Server :: T-SQL Set Identity Seed On Auto Increment +1?
I have stored procedure where i am creating table and setting primary key how to set auto increment ?

set@sql =@sql +
'CONSTRAINT [PK_'+@Table+']

Posted: Nov 20, 2010 11:43 PM

View 4 Replies!   View Related
SQL Server :: Failing Insert When Using Auto Increment?
I am trying to set up an insert command in vb for sql server (not mysql). the following works fine as long as I manually enter a new ASSalesId and don't have this field autoincrement. this field is set up a a primary key. I would like to just use auto increment on this field. but every time I set the field to auto increment the insert fails. if I just remove the reference to this field from the statement the insert fails.

Sub SQLDatabaseEntry()

Posted: Aug 06, 2010 02:49 PM

View 4 Replies!   View Related
Forms Data Controls :: How To Auto Increment ID Coloumn
I made a dataset object having DataTable having 4 colomns: ID,Title,Link,Date.

then I put a ListView that retrive the data from the mydataset object, and I Enabed Editing,Inserting and Deleting.

Now, When I want to add new row, Then 4 TextBoxes shown to enter the ID,Title,Link, Date information.

What i want is to automatically show new ID numberin the ID textbox .

Posted: Nov 23, 2009 05:21 AM

View 12 Replies!   View Related
DataSource Controls :: Getting An Auto-increment Field To Work In SQL
I'm trying to get an IDENTITY column to auto-increment with each new row inserted, so that the field (userid in this case) can be used as a unique identifier.

However, I'm getting this error:


My code looks like this:


I don't understand - if I have to explicitly insert something into my auto-increment column, how do I know what to insert? Isn't the point of an auto-increment column that it's... auto?

Posted: Feb 11, 2010 02:41 PM

View 7 Replies!   View Related
Forms Data Controls :: Auto Increment The Value Of Boundfield?
How can I autoincrement the value of a boundfield column in a gridview ?

Posted: Jan 17, 2011 10:58 AM

View 2 Replies!   View Related
DataSource Controls :: How To Auto-increment Primary Key When Adding A New Row Using Update Method
I followed the official tutorial to create a DAL & Business Logic Layer [URL]. I have a table with a int ID field. I wish to write a function to add a new entry into this table but have the ID field auto-increment.

The ID field is set as the Identity Column and has a Identity Increment & Seed of "1". If I manually go to the table and insert a new record leaving the ID value null it automatically increments. But if I create a C# function to add a new entry I get an error saying that the ID field can't be Null. Is there any way to use the Update method as shown on line 14 below to add a new entry but with it automatically incrementing?

I did create a function called InsertDevice that simply inserts the other fields using a SQL INSERT and it auto-increments fine, just wondering if there is a way to do it using the DataTable and the Update method?


Posted: Jul 26, 2007 03:32 PM

View 3 Replies!   View Related
Forms Data Controls :: Hide Auto Increment Values In Chart Control?
i am using chart control, problem i am facing is that itautomatically generates values in Y-Axis.

As you can see in image , values 0, 3 and 4 are automatically generated. how to hide these automatic generatedvalues.

Posted: Dec 14, 2010 11:58 AM

View 1 Replies!   View Related
Auto Generate Number In Which Is Auto Add In Sql Server Table With Other Data?
I have project in with sql server backend.i want to auto generate a number for particular column.with the auto generated number i want to insert some other data in the same row same table. on button click event.details

railway PNR no.:- want to autogenerat
passenger details:- want to inserted simultaneously

Posted: 1 Week Ago

View 2 Replies!   View Related
Web Forms :: How To Auto Delete And Auto Create Table Data
I have a simple online web system where it possible for the visitors to "play around" with the system. They can like create categories and products and so forth. Everything they create are stored into a database.

What I want is to be able to reset this database with my default values (table data) every n hours.

So for example if we have a bunch of users that have played with the system and created new things. Then I want to be able to make some kode that deletes all data in the tables in this database and fill it with default data. The default data can come from a backup file, or another database with same tables structure or whatever.

I want this task to be done every day at 12 pm or every n hour.

Is this possible (by forexample scheduled webservice tasks or just something as long as it is simple).

Posted: Jun 06, 2010 07:18 AM

View 8 Replies!   View Related
ADO.NET :: How To Display Auto - Incrementing Value From Database In The Same Page Where Inserting Value
in my aspx page user is creating a request and when the request is created a request_id is generated automatically in databse..i want to retreive tht particular request_id and display it on the same web page.

here is my code-

protected void Button1_Click(object sender, EventArgs e)
String selection = DropDownList1.Text.ToString();
String status = "inactive";
ConnectionStringSettings set = ConfigurationManager.ConnectionStrings["WATERMARKING"];
String cns = set.ConnectionString;
SqlConnection cnn = new SqlConnection(cns);
String query = "Insert into REQUESTS (USERNAME,REQUEST_TYPE,STATUS) values ('" + uName + "','" + selection + "','" + status + "')";
SqlCommand cmd = new SqlCommand(query, cnn);
//Response.Write("Request created Successfully ");
//MessageBox.Show("request created successfully");
Label4.Text="request created successfully";
Label5.Text = "Your Request ID is";
Label6.Text = "ID required to Check the Request Status";
catch (Exception err)
//Response.Write("error generated while raising request"+err);
Label4.Text = "request creation error"+err;

here wen a value is getting inserted in REQUESTS table a column named REQUEST_ID gets populated and i want to display that value on the web page

Posted: Feb 08, 2011 10:22 AM

View 7 Replies!   View Related
DataSource Controls :: Get The Identity After Inserting A Record Into A Table Using The Table Adapater?
I cannot for the life of me get the Identity after inserting a record into a table using the Table Adapater.
I am using Text SQL Commands. I have configured the table adapter to "Refresh the Data Table" and the Insert SQL Command:

INSERT INTO [Item] ([name], [description]) VALUES (@name, @description);
SELECT itemId, name, description FROM Item WHERE (itemId = SCOPE_IDENTITY())

The Visual Studio generated Insert Method used the following to execute the InsertCommand

int returnValue = this.Adapter.InsertCommand.ExecuteNonQuery();
return returnValue;

This returns the number of rows affected.

I've tried changing it to: int returnValue = (int)this.Adapter.InsertCommand.ExecuteScalar();
however it returns null;

I've tried playing with the InsertCommand Parameters and creating a new parameter and setting it as a ReturnValue however this doesnt work either.

Posted: May 14, 2006 12:40 AM

View 22 Replies!   View Related
Forms Data Controls :: Error When Inserting Into Table - Cannot Insert Explicit Value For Identity Column In Table
I am working on a web app for an online photo album. It is the last project in Scott Mitchell's book: "ASP.Net 2.0 in 24 hours".

I am creating a page where users can enter new photo images. The functionality for uploading an image will come later. I am working on just inserting a new row into the Pictures table with an optional category, a required title and a required description.

I am getting an error when I try to insert a new row.

Here is a screenshot of the page with a shot of the dropdown list.

The Categories are user-specific. I am getting the correct values retrieved.


There are two pretty simple database tables involved here.

NOTE: The CategoryID and PIctureID are both autoincrement integer columns.


The page uses a DetailsView that uses a SqlDataSource that uses the Pictures table. (The DetailsView's Default Mode property is set to "Insert". The "Enable Inserting" checkbox is also checked.)

The dropdown list uses a dropdown control that uses a SqlDataSource that uses the Categories table.

When the "Insert" button is clicked the CategoryID value associated with selected (Category) Name on the dropdown list will be used along with the Title and Description values to insert a row in to the Pictures table. (If no Category value is selected, then a null value will be used for the CategoryID. This is OK because the CategoryID column in the Pictures table allows nulls.)

My problem is that I am getting this error:

Cannot insert explicit value for identity column in table 'Pictures' when IDENTITY_INSERT is set to OFF.

(FYI: I have the full version of both Visual Studio and SQL Server.)

Here is my source code for the page:


Posted: Aug 11, 2010 02:35 PM

View 3 Replies!   View Related
ADO.NET :: Inserting Data Table Into SQL
Is there an easier way to insert the values contained in a data table generated in ASP into aSQL table without having to loop through all the rows in the data table and insert individually into the SQL table?

Posted: Oct 08, 2010 12:43 PM

View 4 Replies!   View Related
ADO.NET :: Inserting Dataset Into Sql Table?
I need some basic guidance on how I can get my Dataset to insert into a single table instead of sending it to a datagrid.

I get the following columns from DS.Tables["ItemAttributes"]:





I get the following columns from DS.Tables["Item"]:





Item_Id from DS.Tables["Item"] and DS.Tables["ItemAttributes"] are the same

So I would like to insert the data into a table named amaz with columns as follows






My DataSet is fetched using the following code, There can be upto 10 rows in the dataset


Posted: Dec 29, 2010 12:57 PM

View 7 Replies!   View Related
ADO.NET :: Inserting MAX ID Into Table Dynamically?
inserting MAX ID into table dynamically

Posted: Jul 22, 2010 04:27 PM

View 8 Replies!   View Related
Inserting Table On The ASPX File?
I am trying to display a customer's statement of account. Unfortunately, the table always appear on the top of header of my page. I display the table through the code behind file of my page. Attach is the modified image of table that displays on the top of my header.

Posted: Apr 1, 2010, 09:08

View 22 Replies!   View Related
SQL Server :: Inserting Whole Data Table Into Another
If I create a data tabe in C# like so:

datatable t = new DataTable;
DataColum C1 = new DataColum;//ID column
//the same with column C2

Then I fill up the table with some data. Then the goal is to either insert this data or update data in an SQLtable in SQL. If the data is inserted, the ID column in t would be empty, if updated, it would not be. So in the insertion case, the sql query needs to make sure that unique IDs are assigned during insertion, in the update case, it just has to look for the right IDs.How to go about this? Asking because I am only familiar with updating and inserting single lines into a table. One could loop in C# over the datatable t of course and insert or update line by line, but this would probably be slow. Is there a way to write an SQL query like this somehow:

Insert Into SQLTable Values (@t)
And Update like this:
Update SQLTable SET ... Where C1 = @t.C1
Or something like that.
I know that SQL server can create automatic update and insert queries and that you can then type things in C# like


But, this has proven to be super slow on our server, for unknown reasons. I have asked on this forum and got some answers from experts, but was not able to srot out the problem. How can we write a custom SQL query that allow updating and inserting a whole table, instead of just one line at a time?

Posted: Oct 22, 2010 11:21 AM

View 3 Replies!   View Related
Inserting Data From A Listbox Into A Table?
I have the list box control that displaysdata that has been added from the previous order page. I want to insert the data from the listbox control, into a table within the database when the 'checkout' button is clicked.

Posted: Apr 12, 2010 01:37 PM

View 9 Replies!   View Related
MVC :: Selecting And Inserting Dropdownlist Value In To Table?
I have a table MemberProfile with columns FirstName, LastName, Gender and iam displaying complexioncode as a dropdownlist with values fair, very fair, brown and when user selects a value I want to insert that in to table

I have creted a class( LookUpCodes) and written following code

public static IEnumerable<ComplexionCode> ComplexionCodes


now when I click the button FirstName, LastName Gender are inserting in to the table. only Dropdownlist( ComplexionCode ) value is not inserting.

Posted: Mar 31, 2010 02:48 PM

View 1 Replies!   View Related
SQL Server :: How To Make Auto Id In A Table
i have a table in my database.i want to assign a unique id (primary) automatically when each data is to set this one is sql server 2008? i tried but couldnt do it.

Posted: Dec 17, 2010 07:21 PM

View 10 Replies!   View Related
Return Identity Column Value From Table After Inserting Row?
I am inserting data into Employee table using stored procedure.In employee table EmpNo is identity column.Once i insert data into table stored procedure should EmpNo i.e identitycolumn value.

correct my stored procedure to returm EMpNo Identity column after inserting row.

alterprocedureSAR_Sp_AddEmployee(@EmpNamevarchar(10),@CampaignIDint,@startDatedatetime) asinsertintoEmpMastervalues(@EmpName,@CampaignID,@startDate)

Posted: Sep 29 10

View 5 Replies!   View Related
Inserting Data Into Table Using Checkboxes On DataList?
We want to insert records into a table based on what checkboxes the user selects. A screen print is attached.

If a user checks Accounting Clerk and clicks on the button, Add Jobs; the ID of the Job Title Accounting Clerk and the User ID of the user would be added to the job_notify table.

The checkbox is just part of the template and not an actual field.

Here is how the item Template is set up:

<td><asp:LabelID="JobTitleLabel"runat="server"Text='<%# Eval("JobTitle") %>'/></td></tr>

What do I need to do to insert the new data to job_notify table?

Posted: Mar 27, 2009, 15:51

View 1 Replies!   View Related
Databases :: Inserting Date Into Oracle DB Table In C#?
I have tried number of ways to insert date into Oracle Database using below SQL statement. Couldnt get it working.

note I am using Oledb from my C# code to insert into Oracle Table.

INSERT INTO myTable(firstCol,event_timestamp) VALUES('Test1', '5/22/2008 12:00:00 AM');

Posted: Sep 06, 2008 07:11 PM

View 6 Replies!   View Related
DataSource Controls :: Inserting Data Into A SQL Table?
I am building an app (ASP.NET 3.5 + SQL 2005) that allow users to schedule meetings and these meeting will show in theusers to-do list.

One kind ofmeeting, when scheduled, should show intoALL users to-do list.

I have 3 tables:

#1 - Users -> UserID
#2 - Meetings -> MeetingID
#3 - Member_Meeting -> UserID+MeetingID

What I need is:

Based on the scheduled meeting, read all users from table #1and add their info in the table # 3 with the MeetingID (which I can get from the UI, because it will happen when they create the meeting).

I have been browsing about it, but so far, I couldn't find a good source of info to start with.

Posted: Jan 19, 2010 08:30 PM

View 5 Replies!   View Related
State Management :: Inserting To A Table But Expecting The ID?
how can i insert a record to a table that needs an ID from another table row that does not inserted yet ?lets say i have a product add screen, and there is a product details tab. product details table needs product ID but product is not inserted yet. so i tried to store the product details rows in a viewstate but it wont work. every time i added the row its clering the viewstate and adding the last row that i added.

Posted: Jul 08, 2010 11:35 AM

View 11 Replies!   View Related
Copyright 2005-08, All rights reserved