.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Help needed in inserting into the table

Posted By:      Posted Date: October 27, 2010    Points: 0   Category :Sql Server


I have 2 tables, one is master table and another person table. In master table one of the field is autogenerated.

I have a SP which has 2 insert statements to insert into both the tables in that case How can I get the autogenerated ID from the first table to insert into the 2nd table ie) masterid to the person master id field in person table. As the insert is at the same time to both the tables. A single sp will do the insert.

View Complete Post

More Related Resource Links

Fetch Identity column just after inserting a row in table

Hi, Please help me with this question. I have a table and I insert a row into it. How can i select the latest inserted row? Can the 'inserted table' keyword be used outside trigger? ( I mean can we use it in above scenario?? If yes how)   Thanks in advance Tiya

inserting an array of data into a database table

im looking to insert an array of information into a database tableessentially what id like to do is something like this:            objCmd = New OleDb.OleDbCommand("INSERT INTO pluINFO VALUES *", objConn)            For j = 0 To 265                objCmd.Parameters.Add( info(j) )            Next this code gives me a syntax error for the insert statement is there anyway i can set the insert statement that would allow me to add each element of the array(looping through rather than hardcoding several hundred entries) into the table?any input appreciatedThanks

Get inserted ids when inserting from User Defined Table Type

Imagine this procedure:   CREATE PROCEDURE [dbo].[insertActive] ( -- Add the parameters for the stored procedure here @p_data dbo.activeUpdate readonly) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. insert into dbo.active (name,stateid) select name,stateid from @p_data END How can I get the ids of the rows that have been inserted?  I tried searching the net and the forums but could not find anything. Thanks for any and all help, Gareth.

Delete objects from table using another table to select rows - help needed

I have one table named 'dbo.ac_Products'Within this table there is a column named 'ProductId'There is also another table named 'dbo.ac_CatalogNodes'Within this table there is a column named 'CatalogNodeId'and a column named 'CatalogNodeType'I need to delete all the rows from 'dbo.ac_Products' and 'dbo.ac_CatalogNodes' where 'ProductId' = 'CatalogNodeId' and 'CatalogNodeType' = 1Any help would be greatly appreciated!

Problem Facing While Inserting records into table which os dynamicaly created

Hi,I have created table into database dynamicaly,while inserting records into that dynamic table i faced problem.The name "STD000001" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. this error occured.I created dynamic table by ,declare @STUDENT_Table varchar(50)set @STUDENT_Table = [dbo].[GetStudentTable](@SchoolID)declare @cmd varchar(5000)Set @cmd = 'Create Table  ' + @STUDENT_Table + '(   [student_id] [varchar](10)NOT NULL,    [school_id] [varchar](50)NULL,    [class1] [varchar](50)NULL,    [division1] [varchar](50)NULL,    [educalis_id] [varchar](16)NULL,    [roll_no] [varchar](10)NULL,    [first_name] [varchar](50)NULL,    [middle_name] [varchar](50)NULL,    [last_name] [varchar](50)NULL,    [gender] [varchar](6)NULL,    [father_name] [varchar](50)NULL,    [mother_name] [varchar](50)NULL,    [father_office_address] [varchar](200)NULL,    [mother_office_address] [varchar](200)NULL,    [home_address] [varchar](200)NULL,    [father_mobile_no] [varchar](10)NULL,    [mother_mobile_no] [varchar](10)NU

pushing 2columns of one table to another table after filtering(eliminating nulls & inserting only ip

hi thankz in advance,i have 2 tables t1 and t2in t1 i have 4 columns from that i want to insert only 2 columns to another table t2 i only want to send data which is in the form of ip adress like( eliminating nulls and other data.plz suggest me is it possible to write a query or i need to do it programetically.thankz a lot..

Table popup control needed

Hi i got a Html table with Database names displayed in it , now when i hover overthen the need to display images with the path is also saved in the database , so i would have to add some asp.net control in the HTML Table  ,  No Javascript , i have tried it and when i search for names in the database the pics in the table are not where they belong . Need asp.The names are displayed via int howmany=0;while(read.Read()){howmany++;ShowinTable(read["Code"].ToString(),howmany);}Thanks any for suggetions.

inserting one table data to another after filtering nulls and duplicates

hi i have tbl_ip i want to filter nulls and duplicate to my tbl_ipfilter can u suggest me a stored procedure for this. data of tbl_ip is like below . ip NULL NULL NULL

Problem when Inserting xml data into a table using OpenXml

Hi, i stuck with a problemam trying to insert data from xml file to sql server.i made query like thisSET NOCOUNT ON DECLARE @hDoc INT EXEC sp_xml_preparedocument @hDoc OUTPUT, '<NewDataSet>  <xs:schema id=''NewDataSet'' xmlns='''' xmlns:xs=''http://www.w3.org/2001/XMLSchema'' xmlns:msdata=''urn:schemas-microsoft-com:xml-msdata''>  <xs:element name=''Job''>     <xs:complexType>      <xs:sequence>        <xs:element name=''BillToNo'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''Colors'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''CompanyNo'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''CsrCode'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''CsrName'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''CustomerPoNo'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''DivisionOriginal'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''EstimateNo'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''FinalDeliveryDate'' type=''xs:string'' minOccurs=''0'' /> <xs:element name

inserting data to Users Table in ASPNETDB from Create User Wizard


When a user starts a membership using the Create User wizard supplied by the aspnetdb profile service, I need to add a field to a table in aspnetdb and upon clicking the ContinueButtonClick insert some data.  The field I'll add is "SubscId".  My first question is what table is best for this - Users or Membership?

Secondly, what is the best way to insert new data for this scenario?  code behind?  markup?  Can someone provide basic syntax of insert code in code behind for this scenario?

Inserting and querying data on the same table


I need to implement a logic where in I insert or update a table in a loop.If the record is inserted then I need to update the table.To check this I have given IF NOT EXISTS statement with a query. But IF NOT EXISTS always returns true, so many records are getting inserted and update always fails

How do I resove this problem

getting error while inserting values into table in sql server 2005

i have connected to sql server n my connection string is

conn.ConnectionString =

"data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\subi.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

But i am not able to insert values into the table..

am getting sqlexception error.... and msg as invalid object name "staff" as staff is my table name.. before this i had some problem with connection then i cleared that problem then after that this problem occured.. plz guide me on this ... i need to complete my project as soon as possible

Inserting 15 minute Interval Data in a table


What is the most efficient way of creating a 15 minute increment table. This table needs to continue to increment with time so its not a static table. While loop? how will that affect the performance, if I have to add dates starting 2005 till today and then basically after that with every hour a value needs to be added.. How can I go about doing that?

I am using SQL 2008

 Thanks -Sarah

Inserting XML into SQL Server 2008 table



I'm generating an XML file from front end, I'm using 4 Data Transfer Object classes comprising of full details of a Customer like CustomerPersonalInfoDTO.cs, CustomerLoginInfoDTO.cs, CustomerPreviousAddressDTO.cs, CustomerAddressInfoDTO.cs.

Everything is fine and XML is also generated, But the problem is with SQL Server Stored Procedure. I've created a table Customer with 20 columns.

CustomerPersonalInfoDTO.cs holds 10 customer fields and CustomerLoginInfoDTO.cs holds another 10 customer fields (total =20)..

I now need to insert at a time these 20 FIELDS into SQL server Customer Table. My XML Data will look like the below:

<?xml version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ?> 
- <CustomerDTO>

- <CustomerPersonalInfo>

Inserting value of a textbox into a table


I have a detailsview, and I was wondering how I can insert value from a textbox instead of a boundfield value. I am able assign value to textbox in code behind. Could I please know of a simple way to do this. Thanks

    <asp:DetailsView ID="DetailsView4" DataSourceID="AccessDataSource6" 
             runat="server" Height="250px" Width="625px" AutoGenerateInsertButton="True" 
             AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" 
             AutoGenerateRows="False" DefaultMode="Insert">
                    <asp:BoundField DataField="PartNumber" HeaderText="PartNumber"
                  SortExpression="PartNumber" HeaderStyle-Width="100" /> 
                  <asp:BoundField DataField="QtyOrdered" HeaderText="QtyOrdered"
                  SortExpression="QtyOrdered" /> 
                  <asp:BoundField DataField="Units" HeaderText="Units"
                  SortExpression="Units" /> 
                   <asp:BoundField DataField="QtyReceived" HeaderText="QtyReceived"

Inserting null value into foreign key table with allow null enabled


Hey guys, 

I have 2 table Table A, Table B.

Table A - Parent Table

ID - Uniqueidentifier not null(PK)

Table B -Child Table              

ID - uniqueidentifier null(FK, TableA)

I have a stored procedure to insert data into Table B, but when I tried to insert a null value into column ID of table B, this error came up:

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tableB_tableA". The conflict occurred in database "database name", table "table A", column 'ID'.

The statement has been terminated.

The insert statement in asp.net is like so:

sqlcommand.parameter.add(New Sqlparameter("ID", Nothing))

I am guessing adding nothing to the null value column is the problem, but i don't know how to fix it... can any1 help me?


The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tableB_tableA". The co

Problem inserting ID value from one SQL table to another using CreateUserWizard



I am designing a registration form where I use CreateUserWizard. I am inserting data into two different tables while use is created. First table is Categories (columns: CustomerID, CatCode) where I insert CatCodes based on selections made in CheckBoxList and second table is Customers (columns: CustomerID, FName, LName, Email) where I register personal details (first, last name, email etc). CustomerID is generated automatically when client registers.

What I want to do is to connect Categories and Customers tables so when client selects CatCodes during registration and selected values are written into the Categories table CatCode column, appropriate CustomerID to be written there as well (in CustomerID column which is a ForeignKey from Cusomers table).

For example: Client is registered, his CustomerID (1001) is created during registration. He also selected three categories (1,2,3) which are written into the Categories table. Now as I have CustomerID in Categories Table as well (ForeignKey from Customer Table CustomerD column), I want generated CustomerID to show up in Categories table so i could later identify what catgories did client 1001 selected.

Category codes (CatCode) is inserted using code behind file in C#:

 protected void CreateUserWizard1_CreatedUser(obje
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend