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

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

How to insert a Record as per collections

Posted By:      Posted Date: September 09, 2010    Points: 0   Category :ASP.Net
Table1 valuescol1             col2---------------------------1                abc2                def3                ghi Table2 valuescol1     col2   col3   col41           1      gh     jk-----------------------------------------Now the Problem is in My coding i taken List<string> li=new List<string>();li.Add("abc");li.Add("def");li.Add("ghj");in a Textbox i am entering abc value then it should get it ID value.My Questions areHow should i assign a value of Col2 value of Table1 as per the data values what we are entering ?User is entering "abc" or "def" or "ghj" only not ID values.....What is the code for that?

View Complete Post

More Related Resource Links

Insert Same Record Multiple Times.

I have a simple form that inserts a record into a SQL table. The fields are: SerialNumTagNumPONumLocationAddressDescription   This works great. However, I have now been asked to have the form insert x number of records at one time. They want to be able to fill out the following fields: PONumLocationAddressDescription and then have texbox where they can add a number and have that number of the same record inserted.    I hope this makes sense.

Cannot INSERT record using Asp.Net Dynamic Data Domain Service Web Applications

 Hi, I am working on a 'Asp.Net Dynamic Data Domain Service Web Application' project using just 2 tables, FAQ_Categories and FAQs. The FAQs table has a foreign key to the FAQ_Categories. The steps are straight forward. Add a new project (Asp.Net Dynamic Data Domain Service Web Applications) Add folders Model ( for Linq2Sql datacontext), Domain (for the Domain Services class) Add Linq2Slql and add the 2 tables to the designer. Build the project. Add the Domain Service Class to the Domain folder. in the wizard select the DataContext, uncheck the Enable Client & Expose ODate checkbox Check bothe table & their corresponding Enable Editing tables checbox Check the Generate Metadata class Click OK. In Global.asax set Scaffold to true and add the DomainService name. Build and run.   Pages List and Detail are working fine. But if I try to insert a new record, I get the error "FaqId is required" Faq_ID is the primary key in the database table and it is set to Identiy. The Datacontext is correct, it marked the FAQ table with <Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_CustomerId", AutoSync:=AutoSync.OnInsert, DbType:="Int NOT NULL IDENTITY", IsPrimaryKey:=true, IsDbGenerated:=true)> _   I tried this using Linq2Sql, Entity Framework, And both in VB and C# with the same result. I am using VS20

Display Inserted Record After Insert Using A FormView

How do I display a record in a FormView once the record has been inserted? I'm able to get the Identity of the new record without anyproblems, but I can't figure out how I should code the _ItemCreated event. Protected Sub FormViewMessageDetail_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) 'Refresh the list to show the new record RepeaterMessages.DataBind() 'Set the .SelectCommand to Select the New Record SqlDataSourceMessageDetail.SelectCommand = "SELECT * FROM Messages WHERE [Id] = " & NewId FormViewMessage.DataBind() FormViewMessage.ChangeMode(FormViewMode.Edit) test.Text = NewId.ToString End Sub Protected Sub SQLDataSourceMessageDetail_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) NewId = e.Command.Parameters("@NewId").Value End Sub

After INSERT Trigger question - how to use value from last added record

Hi, I have a table where one of the fields is defined like [barCodeID] int IDENTITY(1, 1) NOT NULL - so the value in this column is generated automatically. What I want is, after each INSERT, to write this automatically generated value to another table. The simplest would be to do it with an after insert trigger, but don't know how. How to refer to a value from the last added record in a trigger? Thanks

how can insert only new record into another table through trigger

I have on master table in sql in which every time new data is inserted.i just want to copy the new inserted record into another table.How can i do this. below is my trigger but how can it identify only new records should be inserted into second table.please help me and modify it. CREATE TRIGGER CopyRecordToPortInTable ON SmsTable AFTER INSERT AS BEGIN SET NOCOUNT ON; insert into Portintable(smsno,smstext,flag) select (sms,smstext,0) where condition END

record count for subquery which is used for INSERT

My current code is like this

Insert into ReportDetail( Partcipantid, Reportid)

      select distinct ParticipantID , 3 from abc   where

        closed = 0 and ( isnull ( primaryphone, '' )

How to refresh page and dropdown after insert record from popup page


I have a page that is opened in a popup window from the main page. Once i click insert it pops up a message that says you have successfully added blah blah. Then once you click ok it closes the popup page and goes back to the main page. I want to be able to refresh the main page back to how it was when you first land on the page. Here is the code for my insert button:


 <asp:button id="insertButton" 
                    style="background-image:url('Images/Button.gif'); text-align:center;background-color:Transparent; cursor:hand; background-repeat:no-repeat; background-position:left; padding-left:15px; font-family: 'Arial Unicode MS'; font-size: small; font-weight: bold;" 
                    Runat="server" Height="25px" BorderStyle=None ForeColor=White    Text="Insert" 
                    Width="99px" CssClass="style13" CommandName="Insert" OnClientClick="javascript: alert('You have successfully added a New Donor!!');window.open('','_self','');window.close();" />


trying to insert a record into database


 I put in break points, the problem starts when I get to this part:

public void InsertClients(string client_name, string client_lastname, int client_age)
            cmd = new SqlCommand();
            cmd.CommandText = "[dbo].[prcinsert_client]";
            cmd.CommandTimeout = 0;
            cmd.CommandType = CommandType.StoredProcedure;

            cn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["myConnectionString"].ToString());
            cmd.Connection = cn;
            cmd.Parameters.Add("@client_name", SqlDbType.VarChar, 12).Value = client_name;
            cmd.Parameters.Add("@client_lastname", SqlDbType.VarChar, 15).Value = client_lastname;
            cmd.Parameters.Add("@client_age", SqlDbType.Int, 4).Value = client_age;

                cmd.ExecuteNonQuery();  // problem is here will not execute the query.
            catch (SqlException)
                throw; // throw it back to the calling method.


I checked I can get all of my values. Here how I save my value in the bll:

public int Save_Client(string clientname, string clie

Check to see if record exists befor SQL Insert


I would like to check and see if a record exists before doing an insert. Here is the code I have tried:


Imports System.Data
Imports System.Data.SqlClient
Imports Telerik.Web.UI
Imports System.CodeDom
Imports System.Web
Imports System.Web.Security
Imports System.Web.Security.Roles
Imports System.Web.Security.Membership
Imports System.Security
Imports System.Security.Principal.WindowsIdentity

Partial Class template
    Inherits System.Web.UI.Page
    Private Shared prevPage As String = String.Empty

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If (Not IsPostBack) Then
            prevPage = Request.UrlReferrer.ToString()
        End If
    End Sub

    Protected Sub btn_Volunteer_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim IDProfileVolunteer As String = Session("IDProfileVolunteer")
        Dim IDProfileOrganization As String = CType(FormView1.FindControl("hf_IDProfileOrganization"), HiddenField).Value

        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim strconnection, strsqlinsert As String

        Dim currentUser As MembershipUser = Membership.GetUser()
        Dim currentUserId As Gu

writing a function to insert a new record in a table


Pardon me, I'm just getting started with C#, but here goes:

I have an asp.net web page that allows the user to insert a new record in a database table named "featured_properties." The table has 3 fields (propID [int], dtDisplay [datetime], and lastdisplay [datetime]). propID corresponds to a unique id in a different table, which contains a field called "name" [varchar].

To insert a new record into "featured_properties", the user chooses a name from an asp:DropDownList, which is populated by the "name" field in the second table. The value of each name option in the dropdown list is the unique id number for that record, which will also serve as the propID number in featured_properties. This part is working fine.

<asp:DropDownList ID="ListOfProperties" runat="server" 
            DataSourceID="MembersDataSource" DataTextField="PropertyName" 

So I have a control that will provide a value for the "propID" field in the insert.

For the other two datetime fields (dtDisplay and lastdisplay), I've placed asp:Calendar controls on the page. I would like one to provide the value for StartDate and the other to Provide the valu

How to insert record with javascript



How to insert data with javascript?
Is it possible in javascript to use LINQ, or an option that stores the data in a table?

How do I get this?

foreach loop - insert record in table



i createa a data flow task and read the records from a table to recordset.

now i inserted a foreach loop container which needs to go thru each record loaded in recordset from dataflow task. i made enumerator to foreach as ado enumerator and set the ado object source variable to recordset variable name from data flow task. also radiobox , rows in the first table is marked.

i also mapped the variable in foreach loop.


my question is how i can use these variable to insert variable values in antoher table?


mark it as answer if it answered your question :)

Insert record in nested detailsview


Scenario : I have two database tables with one to many relationship. eg:- City and Related news. So I have a gridview(Gridview1) which lists out all the cities and allows edit, delete of the gridview rows. Now since i wanted to display all news for the city , i have a nested gridview as a column in this Gridview1.  This nested gridview displays all the news for the cities. And I have edit, delete buttons for this gridview too - So far, good - works fine.

Now what I would like to do is - To insert a new news item for a city. For this, I attached a detailsview to my nested grid(gridview2), and tried to insert. I need the primary key id of city table from the first grid (gridview1) to insert the news into the second database table and I could not access this value from the parent gridview.  My gridview1 does not have datakeyname, it is programatically bound.

Also, When the gridview/detailsview is nested, it does not get listed in the event-handler list. So I cannot use say, detailsview1_iteminserting. I do not how to add this event handler

Has anybody done anything similar? When I started, it looked like a pretty straightforward thing - There must be some way to do this. But I just can't get it to work.  Any ideas? How do you usually insert into the child table in a one-to-many relationship? Should i jus

Need Query to find out the latest record insert in database


Here is my table contain the following fields

   ID    UID    OID   Date  

   1      20       1    2010-11-03 12:22:44.217

   2      30       1     2010-11-03 12:01:09.090  

   3      20      2     2010-11-03 12:22:44.217

   4      40      2   2010-11-03 12:01:09.090

i need the result like

UID   OID    Date

 30     1        2010-11-03 12:01:09.090  

 40     2         2010-11-03 12:01:09.090  

Please help me

20 2 2010-11-03 12:22:44.217

Record Count on MERGE Statement on Insert,Update,Delete


HI All,

How can I get the numbers of records affected in the Merge statement, INSERT,UPDATE,DELETE  separately and store it in a variable so I can get it in the application side? 



khrizz tell

Cannot insert new record into multiple tables thru. sql 2005 View

I have a sql server 2005 database containing several tables: Orders, Shipping, and Planning.  They are joined together in the sql view V_Main.  I also have a ms access 2007 mdb that links to V_Main via odbc.  I created an access form using the view V_Main as the record source.  I cannot insert a new record into each of the 3 base tables using V_Main as the record source.  A new record is inserted into only one table.
I did find a suggestion in another forum that suggested copying the sql that creates the view into the record source, rather than the name of the view.  This does work, but adds another place to be updated manually should and other table be added to the view in the future.
I did verify that all tables have primary keys.
How can I add a new record for each of the 3 base tables using the view as the record source?  What is the code that could be placed in vb of the form?
Any suggestions would be helpful.
Thank you.

How to avoid that BCP.exe insert stops when duplicate record exist?

I’m a migration consultant at Infor (Infor and Microsoft have a partnership) and we use in case the target database is SQL Server the bcp.exe to upload the data from old Baan-systems and legacy-systems into our core product “Infor ERP LN”.

The big, big problem with the bcp.exe is that loading stops as soon as a duplicate record exists. Is it possible to extend the bcp.exe to be able to load in append- and conventional mode like Oracle sql loader?
This is the big advantage of the Oracle High performance loader (sqlldr) where you can load the data in Conventional mode which creates the records per row!

I also heard that the bcp.exe will be replaced in future by another utility. We really hope this new utility don’t stop by each duplicate! Maybe you can provide me with more details about the new utility?

Many thanks in advance!
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