MULTIPLE VALUES INSERTION INTO MULTIPLE TEXTBOXES

I HAVE TO INSERT DATA INTO DATABASE TABLE FROM TEXTBOXES.DTABASE STRUCTURE
table name Insert_damo_1
name nvarchar(50)
lastname nvarchar(50)
addr  nvarchar(50)
C# CODING
        SqlConnection cnn1 = new SqlConnection("my connection string");
        cnn1.Open();
        SqlCommand cmd;
        String[] nam1 = {TextBox1.Text,TextBox2.Text,TextBox3.Text };
        foreach (String na in nam1)
            cmd = new SqlCommand("insert into Insert_damo_1(name) values(@name)",cnn1);
            cmd.Parameters.AddWithValue("@name",na);
            cmd.ExecuteNonQuery();
        String[] last1 = { TextBox4.Text, TextBox5.Text, TextBox6.Text };
        foreach (String la1 in last1)
            cmd = new SqlCommand("insert into Insert_damo_1(lastname) values(@lastname)", cnn1);
            cmd.Parameters.AddWithValue("@lastname", la1);
            cmd.ExecuteNonQuery();
        String[] ad1 = { TextBox7.Text, TextBox8.Text, TextBox9.Text };
        foreach (String a1 in ad1)
            cmd = new SqlCommand("insert into Insert_damo_1(addr) values(@addr)", cnn1);
            cmd.Parameters.AddWithValue("@addr", a1);
            cmd.ExecuteNonQuery();
        cnn1.Close();
        Response.Write("insert successful");
I GOT THE RESULT AS
name          lastname
 address
a                  null                     null
b                  null                     null
c                  null                     null
null             d                         null
null             e                         null
null             f                          null
null            null                      g
null            null                      h
null            null                      i
1. I WANT RESULT WITHOUT NULL
2. IF USER DOES'T INSERT ANYTHING IN A TEXT BOX THEN ONLY NULL IS INSERTED AT THAT PLACE
ANY HELP WILL BE DEEPLY APPRECIATED.
THANK YOU. 

Try this
cnn1.Open();
SqlCommand cmd;
String[] nam1 = {TextBox1.Text,TextBox2.Text,TextBox3.Text };
String[] last1 = { TextBox4.Text, TextBox5.Text, TextBox6.Text };
String[] ad1 = { TextBox7.Text, TextBox8.Text, TextBox9.Text };
cmd = new SqlCommand("insert into Insert_damo_1(name,lastname,addr) values(@name,@lastname,@addr)",cnn1);
cmd.Parameters.Add("@name", SqlDbType.VarChar);
cmd.Parameters.Add("@lastname", SqlDbType.VarChar);
cmd.Parameters("@addr", SqlDbType.VarChar);
for(int i; i < nam1.Length; i++)
cmd.Parameters["@name"].Value = nam1[i];
cmd.Parameters["@lastname"].Value = last1[i];
cmd.Parameters["@addr"].Value = last1[i];
cmd.ExecuteNonQuery();
cnn1.Close();
Response.Write("insert successful");
jdweng

Similar Messages

  • Insert values to one table based on a value inserted into another table

    Hi,
    I've got a form based off a report which creates a new project. I've added an additional process to this form to insert four new values into another table as soon as the new project is created and the PK for that project is generated. This was working last week (of course!) and now seems to not work at all. It's complaining that the PK I was getting from my first insert was null. Here is one the the statements in my process I'm trying to run:
    insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY')) FROM dual), 0, '', :P45_PROJECT_SEQ, sysdate, :APP_USER);
    The complaint I get that it's getting null where :P45_PROJECT_SEQ should be.
    Thoughts?
    Thanks,
    Jon

    Hi Andy,
    Thanks for the tip. Those two values didn't match and I updated them so they do and I'm still getting a "cannot insert NULL..." error.
    When I turn on debug I see that I'm getting the PK and I see the value. Here's my debug output:
    0.24: ...Process "Get PK": PLSQL (AFTER_SUBMIT) declare function get_pk return varchar2 is begin for c1 in (select PROJECT_SEQ.nextval next_val from dual) loop return c1.next_val; end loop; end; begin :P45_PROJECT_SEQ := get_pk; end;
    0.25: ...Session State: Saved Item "P45_PROJECT_SEQ" New Value="252"
    0.25: ...Process "Process Row of PROJECT": DML_PROCESS_ROW (AFTER_SUBMIT) #OWNER#:PROJECT:P45_PROJECT_SEQ:PROJECT_SEQ|IUD
    0.26: ...Session State: Save "P45_PROJECT_SEQ" - saving same value: "252"
    0.26: ...Process "reset page": CLEAR_CACHE_FOR_PAGES (AFTER_SUBMIT) 45
    0.27: Nulling cache for application "120" page: 45
    0.27: ...Process "Add Week Groups": PLSQL (AFTER_SUBMIT) insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY')) FROM dual), 0, '', :P45_PROJECT_SEQ, sysdate, :APP_USER); insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY') +
    0.28: Encountered unhandled exception in process type PLSQL
    0.28: Show ERROR page...
    0.28: Performing rollback...
    I notice that when it runs my process "Add Week Groups" it's not displaying all of the SQL. But the SQL is fine, it's right here:
    insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY')) FROM dual), 0, '', :P45_PROJECT_SEQ, sysdate, :APP_USER);
    Hmmm....what about the "reset page" action in the last of the 0.26 lines?
    Thanks,
    Jon

  • ORA-22908: reference to NULL table value (insert into nest)

    Hi all,
    When attempting to insert a record into a nested table I get the above error (ORA-22908...). I've read what the error means, but to be honest it's a bit confusing. I'm wondering if someone could shed some light on the topic for me.
    The insert statement I'm using is:
    IF (:P50_CASEN IS NOT NULL) THEN
    INSERT INTO TABLE(SELECT LSMCS FROM SIN WHERE CASEN = :P50_CASEN)
    VALUES
    (LSMC_TY(:P50_C1,:P50_C2,:P50_C3,:P50_C4));
    END IF;
    The table def/DDL for SIN is:
    CREATE TABLE "SIN"
    (     "ID" NUMBER NOT NULL ENABLE,
         "CASEN" NUMBER,
         "EB" VARCHAR2(100),
         "EO" DATE,
         "ED" DATE,
         "NAME" VARCHAR2(100),
         "TITLE" VARCHAR2(100),
         "STATUS" VARCHAR2(20),
         "SPR" VARCHAR2(100),
         "BUNIT" VARCHAR2(100),
         "ECM" VARCHAR2(100),
         "PHONE" VARCHAR2(30),
         "REGION" VARCHAR2(30),
         "CAT" VARCHAR2(30),
         "PII" VARCHAR2(10),
         "RTN" VARCHAR2(10),
         "TCSIRC" VARCHAR2(10),
         "USCERT" VARCHAR2(10),
         "OCCS" VARCHAR2(10),
         "NOTES" VARCHAR2(4000),
         "LSMCS" "LSMCS_NT"
    NESTED TABLE "LSMCS" STORE AS "LSMCS_NT_TAB"
    RETURN AS VALUE
    CREATE OR REPLACE TRIGGER "BI_SIN"
    before insert on "SIN"
    for each row
    begin
    if :NEW."ID" is null then
    select "SIN_SEQ".nextval into :NEW."ID" from dual;
    end if;
    end;
    ALTER TRIGGER "BI_SIN" ENABLE
    ++++++++++++
    The DDL for the type is:
    CREATE OR REPLACE TYPE "LSMC_TY" AS OBJECT
    (C1 VARCHAR2(50),
    C2 VARCHAR2(50),
    C3 VARCHAR2(10),
    C4 VARCHAR2(4000));
    +++++++
    Any help would be much appreciated...

    A simplified example.
    SQL> select * from sin
      2  where id = 1
      3  /
            ID
    LSMCS(C1, C2, C3, C4)
             1
    LSMC_NT(LSMC_TY('APC', 'TOOTING', 'JUST A GUY', 'http://radiofreetooting.blogspot.com'))
    SQL> insert into  table(select s.lsmcs from sin s where s.id=1) t
      2  values ( LSMC_TY('HAROLD SAXON', 'UTOPIA', 'MASTER', 'http://www.haroldsaxon.co.uk/'))
      3  /
    1 row created.
    SQL> select * from sin
      2  where id = 1
      3  /
            ID
    LSMCS(C1, C2, C3, C4)
             1
    LSMC_NT(LSMC_TY('APC', 'LONDON', 'JUST A GUY', 'http://radiofreetooting.blogspot.com')
    , LSMC_TY('HAROLD SAXON', 'UTOPIA', 'MASTER', 'http://www.haroldsaxon.co.uk/'))
    SQL> This is basically what you have. So I think you need to simplify your implementation to get it working and then complicate it until you discover what breaks it :)
    Cheers, APC

  • Loop over form values & insert into db

    Form
    prod_id     prod_name       prod_price    prod_status
    001         product 001     1.00          1            
    002         product 002     2.00          1      
    003         product 003     3.00          0      
    004         product 004     4.00          0      
    Form Dump
    prod_name      product 001,product 002,product 003,product 004
    FIELDNAMES     prod_id, prod_name, prod_price, prod_status
    prod_price     1.00,2.00,3.00,4.00
    prod_status    1,1,0,0
    prod_id        001,002,003
    I want to update a few fields, prod_price and prod_status. I submit these values to my update page but I'm not sure how to loop over these values and update by the prod_id. In my update page I'm using cfdump and I see the structure of the form, the fieldnames as well as the prod_id, prod_name, etc and their values.
    My question is how do I loop over these form values so I'll be able to update by each prod_id? I've played around with looping over the form collection values but no luck.

    When I do stuff like this, I append the "id" value to the end of each form field.  That enables me to ensure the other fields match up.
    When processing the form, I generally do something like this:
    <cfloop list="#form.fieldnames# index="ThisField">
    <cfif left(ThisField, 9) is "prod_name">
    <cfscript>
    ThisID = removechars(thisfield, 9);
    ThisName = form["prod_name" & ThisID];
    same for other fields
    Then do something with those variables.

  • Insert into table.

    i want insert rows in table b having 5 columns from table a having 3 columns how to achieve that ?
    eg..
    table a
    column 1
    column 2
    column 3
    table b
    column 1
    column 2
    column 3
    column 4
    column 5...
    i used beloc script
    insert into usename.table b @dblink ( column 1,column 2,column 3) select column 1,column 2,column 3 from table a
    but i m gettin error
    ORA-01400: cannot insert NULL into
    plz suggest.
    Edited by: user511621 on Feb 4, 2010 11:23 PM

    If the following:
    insert into usename.table b @dblink ( column 1,column 2,column 3) select column 1,column 2,column 3 from table araises ORA-01400 then either column4 or column5 are NOT NULL.
    1) discover what are the not null column executing
    DESC tableBfrom sql*plus prompt.
    2) Provide values for not null columns
    For example if column4 is a number and you want to insert 0 as value
    insert into usename.table b @dblink ( column 1,column 2,column 3,column4)
    select column 1,column 2,column 3,0 from table aMax
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/01/31/le-direttive-di-compilazione-pragma/]

  • Split one column  value and insert into multiple columns

    hi
    am new to plsql .
    i want to split a characters from one column and insert into multiple columns
    i tried used substr function the symbol ',' vary his place dynamically ,so i can't apply substr function.
    for eg:  before split
    col1 :
    col2 :
    col3 :
    col4 :
    colu5: adsdf,fgrty,erfth,oiunth,okujt
    after split
    col1 :adsd
    col2 :fgrty
    col3 :erfth
    col4 :oiunth
    col5 : adsdf,fgrty,erfth,oiunth,okujt
    can anyone help me
    thanks
    Edited by: 800324 on Dec 23, 2010 8:28 AM
    Edited by: 800324 on Dec 23, 2010 8:36 AM

    How about:
    SQL> create table t
      2  (col1 varchar2(30)
      3  ,col2 varchar2(30)
      4  ,col3 varchar2(30)
      5  ,col4 varchar2(30)
      6  ,col5 varchar2(30)
      7  );
    Table created.
    SQL> insert into t (col5) values ('adsdf,fgrty,erfth,oiunth,okujt');
    1 row created.
    SQL> insert into t (col5) values ('x,y');
    1 row created.
    SQL> insert into t (col5) values ('a,b,c,d');
    1 row created.
    SQL> select * from t;
    COL1                           COL2                           COL3                           COL4                           COL5
                                                                                                                                adsdf,fgrty,erfth,oiunth,okujt
                                                                                                                                x,y
                                                                                                                                a,b,c,d
    3 rows selected.
    SQL>
    SQL> merge into t a
      2  using ( with t1 as ( select col5||',' col5
      3                       from   t
      4                     )
      5          select substr(col5, 1, instr(col5, ',', 1, 1)-1) col1
      6          ,      substr(col5, instr(col5, ',', 1, 1)+1, instr(col5, ',', 1, 2)- instr(col5, ',', 1, 1)-1) col2
      7          ,      substr(col5, instr(col5, ',', 1, 2)+1, instr(col5, ',', 1, 3)- instr(col5, ',', 1, 2)-1) col3
      8          ,      substr(col5, instr(col5, ',', 1, 3)+1, instr(col5, ',', 1, 4)- instr(col5, ',', 1, 3)-1) col4
      9          ,      rtrim(col5, ',') col5
    10          from   t1
    11        ) b
    12  on ( a.col5 = b.col5 )
    13  when matched then update set a.col1 = b.col1
    14                             , a.col2 = b.col2
    15                             , a.col3 = b.col3
    16                             , a.col4 = b.col4
    17  when not matched then insert (a.col1) values (null);
    3 rows merged.
    SQL> select * from t;
    COL1                           COL2                           COL3                           COL4                           COL5
    adsdf                          fgrty                          erfth                          oiunth                         adsdf,fgrty,erfth,oiunth,okujt
    x                              y                                                                                            x,y
    a                              b                              c                              d                              a,b,c,d
    3 rows selected.
    SQL> Assuming you're on 9i...

  • Insert into two tables, how to insert multiple slave records

    Hi, I have a problem with insert into two tables wizard.
    The wizard works fine and I can add my records, but I need to enter multiple slave table records.
    My database:
    table: paper
    `id_paper` INTEGER(11) NOT NULL AUTO_INCREMENT,
    `make` VARCHAR(20) COLLATE utf8_general_ci NOT NULL DEFAULT '',
    `model` VARCHAR(20) COLLATE utf8_general_ci NOT NULL DEFAULT '',
    `gsm` INTEGER(11) NOT NULL,
    PRIMARY KEY (`id_paper`)
    table: paper_data
    `id_paper_data` INTEGER(11) NOT NULL AUTO_INCREMENT,
    `id_paper` INTEGER(11) NOT NULL,
    `value` DOUBLE(15,3) NOT NULL,
    `nanometer` INTEGER(11) NOT NULL,
    PRIMARY KEY (`id_paper_data`)
    I need to add multiple fields "value" and "nanometer"
    Current form looks like this:
    Make:
    Model:
    Gsm:
    Value:
    nanometer:
    I need it to look like this:
    Make:
    Model:
    Gsm:
    Value:
    nanometer:
    Value:
    nanometer:
    Value:
    nanometer:
    Value:
    nanometer:
    and so on.
    The field "id_paper" in table paper_data needs to get same id for entire transaction. Also how do I set default values for each field "nanometer" on my form the must be different (370,380,390 etc)?
    Thanks.

    you can find an answer here: http://209.85.129.132/search?q=cache:PzQj57dsWmQJ:www.experts-exchange.com/Web_Development /Software/Macromedia_Dreamweaver/Q_23713792.html+Insert+Into+Two+Tables+Wizard&cd=3&hl=lt& ct=clnk&gl=lt
    This is a copy of the post:
    Hi experts,
    Im using ADDT to design a page that needs to insert one record into a master ALBUMS table, along with three records into a GENRES table, all linked by the primary, auto-incremented ALBUMS. ALBUM_ID.
    Ive tried many different ways of combining the Insert into Multiple Tables wizard and the insert record wizard with Link Transactions, all with no luck.  Either only the album info gets inserted, or a ALBUM_ID cannot be null error from MySQL.  Here is the structure of the tables
    ALBUMS
    ALBUM_ID, INT(11), Primary, Auto_Increment
    alb_name, varchar
    alb_release, YEAR
    USER_ID, int
    alb_image, varchar
    GENRES
    ALBUM_ID, int, NOT NULL
    GENRE_ID, int, NOT NULL
    ID, int, primary, auto-increment
    Many thanks in advance...
    ==========================================================================================
    //remove this line if you want to edit the code by hand
    function Trigger_LinkTransactions(&$tNG) {
      global $ins_genres;
      $linkObj = new tNG_LinkedTrans($tNG, $ins_genres);
      $linkObj->setLink("ALBUM_ID");
      return $linkObj->Execute();
    function Trigger_LinkTransactions2(&$tNG) {
      global $ins_genres2;
      $linkObj = new tNG_LinkedTrans($tNG, $ins_genres2);
      $linkObj->setLink("ALBUM_ID");
      return $linkObj->Execute();
    function Trigger_LinkTransactions3(&$tNG) {
      global $ins_genres3;
      $linkObj = new tNG_LinkedTrans($tNG, $ins_genres3);
      $linkObj->setLink("ALBUM_ID");
      return $linkObj->Execute();
    //end Trigger_LinkTransactions trigger
    //-----------------------Different Section---------------------//
    // Make an insert transaction instance
    //Add Record Genre 1
    $ins_genres = new tNG_insert($conn_MySQL);
    $tNGs->addTransaction($ins_genres);
    $ins_genres->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "VALUE", null);
    $ins_genres->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $detailValidation);
    $ins_genres->setTable("genres");
    $ins_genres->addColumn("GENRE_ID", "NUMERIC_TYPE", "POST", "GENRE_ID");
    $ins_genres->addColumn("ALBUM_ID", "NUMERIC_TYPE", "VALUE", "");
    $ins_genres->setPrimaryKey("ID", "NUMERIC_TYPE");
    // Add Record Genre 2
    $ins_genres2 = new tNG_insert($conn_MySQL);
    $tNGs->addTransaction($ins_genres2);
    $ins_genres2->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "VALUE", null);
    $ins_genres2->setTable("genres");
    $ins_genres2->addColumn("GENRE_ID", "NUMERIC_TYPE", "POST", "GENRE_ID2");
    $ins_genres2->addColumn("ALBUM_ID", "NUMERIC_TYPE", "VALUE", "");
    $ins_genres2->setPrimaryKey("ID", "NUMERIC_TYPE");
    // Add Record Genre 3
    $ins_genres3 = new tNG_insert($conn_MySQL);
    $tNGs->addTransaction($ins_genres3);
    $ins_genres3->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "VALUE", null);
    $ins_genres3->setTable("genres");
    $ins_genres3->addColumn("GENRE_ID", "NUMERIC_TYPE", "POST", "GENRE_ID3");
    $ins_genres3->addColumn("ALBUM_ID", "NUMERIC_TYPE", "VALUE", "");
    $ins_genres3->setPrimaryKey("ID", "NUMERIC_TYPE");
    =========================================================================================
    Hi Aaron,
    Nice job!!
    $ins_albums->registerTrigger("AFTER", "Trigger_LinkTransactions2", 98);
    $ins_albums->registerTrigger("AFTER", "Trigger_LinkTransactions3", 98);
    These lines, right? :-( Sorry I forgot to mention that
    Thanks a lot for the grading!

  • Insert into multiple table view

    I have a view with multiple table query and and INSTEAD OF trigger on the view that inserts into multiple tables. When I attempt to do a commit out of a ADF Creation Form, I get the following error: ORA-01779: cannot modify a column which maps to a non key-preserved table ORA-06512: at line 1.
    Has anyone had success inserting into multiple tables via a view that has more than one table?
    Thanks,
    Lisa

    Lisa,
    Sounds like your instead-of trigger may not be being called and you are trying to insert directly into the view.
    I did write a [url http://stegemanoracle.wordpress.com/2006/03/15/using-updatable-views-with-adf/]blog entry about using a view with instead-of triggers last year.
    John

  • Inserting into multiple tables on one form using UIX

    We are developing an application using struts and UIX. We would like to be able to insert into three tables on one form(view). How can we accomplish this?

    This is more of an ADF question, you'll need to set up view object, than just drag it from the data control palette like normal.
    If it's not already set up as a view in the db (split into multiple tables), you'll need to create a view object that includes all the fields you want, based on multiple entity objects.

  • BizTalk 2013 R2 - Oracle client (Insert into Multiple tables) CompositE Transaction

    I know there is Composite Transaction of  inserting into multiple tables in SQL.
    Is there a way where we can have inserts into multiple table at once ? If yes, can anyone please provide step by step procedure to achieve this  
    MBH

    Here is a link on using Oracle DB w/ composite operations: 
    Performing Composite Operations on Oracle Database by Using BizTalk Server
    Rachit
    Please mark as answer or vote as helpful if my reply does

  • Stored procedure to insert into multiple tables in sql server 2012, using id col from one table to insert into the other 2

    Hi all,
    Apologies if any of the following sounds at all silly but I am fairly new to this so here goes...
    I have 3 tables that require data insertion at the same time. The first table is the customers table, I then want to take the automatically generated custid from that table and inser it into 2 other tables along with some other data
    Here's what I have so far which does not work:
    CREATE PROCEDURE CustomerDetails.bnc_insNewRegistration @CustId int,
    @CompanyName varchar(100),
    @FirstName varchar(50),
    @LastName varchar(50),
    @Email nvarchar(254),
    @HouseStreet varchar(100),
    @Town smallint,
    @County tinyint,
    @Postcode char(8),
    @Password nvarchar(20)
    AS
    BEGIN
    begin tran
    insert into CustomerDetails.Customers
    (CompanyName, FirstName, LastName, EmailAddress)
    Values (@CompanyName, @FirstName, @LastName, @Email)
    set @CustId = (select CustId from inserted)
    insert into CustomerDetails.Address
    (CustomerId, HouseNoAndStreet, Town, County, PostCode)
    values (@CustId, @HouseStreet, @Town, @County, @Postcode)
    insert into CustomerDetails.MembershipDetails
    (CustomerId, UserName, Password)
    values (@CustId, @Email, @Password)
    commit tran
    END
    GO
    If anyone could help with this I would very much appreciate it as I am currently building an online store, if there's no registration there's no customers.
    So to whom ever is able to help, I thank you whole heartedly :)

    I hope by now it is apparent that statements like "doesn't work" are not particularly helpful. The prior posts have already identified your first problem.  But there are others.  First, you have declared @CustID as an argument for your
    procedure - but it is obvious that you do not expect a useful value to be supplied when the procedure is executed.  Perhaps it should be declared as an output argument so that the caller of the procedure can know the PK value of the newly inserted customer
    - otherwise, replace it with a local variable since it serves no purpose as an input argument.
    Next, you are storing email twice.  Duplication of data contradicts relational theory and will only cause future problems. 
    Next, I get the sense that your "customer" can be a person or a company.  You may find that using the same table for both is not the best approach.  I hope you have constraints to prevent a company from having a first and last name (and
    vice versa).
    Next, your error checking is inadequate.  We can only hope that you have the appropriate constraints to prevent duplicates.  You should expect failures to occur, from basic data errors (duplicates, null values, inconsistent values) to system issues
    (out of space).  I'll leave you with Erland's discussion for more detail:
    erland - error handling.
    Lastly, you should reconsider the datatypes you are using for the various bits of information.  Presumably town and county are foreign keys to related tables, which is why they are numeric.  Be careful you don't paint yourself into a corner with
    such small datatypes.  One can also debate the wisdom of using a separate tables for Town and County (and perhaps the decision to limit yourself to a particular geographic area with a particular civic hierarchy). Password seems a little short to me. 
    And if you are going to use nvarchar for some strings, you might as well use it for everything - especially names.  Also, everyone should be security conscious by now - passwords should be encrypted at the very least.
    And one last comment - you really should allow 2 address lines. Yes, two separate ones and not just one much larger one.

  • Insert into multiple tables; grab id from first

    I apologize if this has been answered elsewhere, but I tried
    searching and got no results.
    I'm trying to insert the contents of one form into two
    tables. After inserting some fields into one table, I want to grab
    the key/id from the first table into the second table with the
    other fields.
    I've tried a few different things, including trying to use
    SCOPE_IDENTITY(), but just kept getting lots of errors.
    The current version of my code works perfectly, *except for
    the fact that it doesn't insert the ID*!
    Can anyone tell me what I'm doing wrong? or offer another way
    of doing this?
    Thanks for your help, as usual.

    MarianneStone wrote:
    > The current version of my code works perfectly, *except
    for the fact that it doesn't insert > the ID*!
    > Can anyone tell me what I'm doing wrong?
    The EmployeeID is not inserted because the getMyID query
    cannot find the newly inserted record. When using a UUID to
    identify the new records ..
    <cfquery name="qAddDeptHead" datasource="#db#"
    result="result">
    INSERT INTO Employee(... , EmpUUID)
    VALUES ( ... , '#CreateUUID()#')
    </cfquery>
    You have to use that _same_ UUID to find the record, _not_
    create a new one.
    <cfquery name="getMyID" datasource="#db#">
    SELECT EmployeeID, EmpUUID
    FROM Employee
    WHERE Employee.EmpUUID='#UseTheSameUUIDFromTheFirstQuery#'
    </cfquery>
    As an aside, you could probably do this in two queries not
    three. Just drop the second SELECT query and use an INSERT
    INTO/SELECT .. FROM Table statement instead. Plus you should also
    consider using cfqueryparam for your query parameters. It has many
    benefits.
    http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_p-q_18.html#1102474
    > Can anyone ... offer another way of doing this?
    There are a few options. For ColdFusion 8, you could use the
    result attribute. After running the INSERT you can grab the new
    EmployeeID by using #yourResult.IDENTITYCOL#
    <cfquery name="qAddDeptHead" datasource="#db#"
    result="yourResult">
    INSERT INTO Employee ( Columns here )
    VALUES (... values here ...)
    </cfquery>
    For earlier versions, you can either use SCOPE_IDENTITY() or
    a UUID value - as you are currently doing now.
    > I've tried a few different things, including trying to
    use SCOPE_IDENTITY(),
    > but just kept getting lots of errors.
    If you use SCOPE_IDENTITY() turn off the rowcount, or the
    query variable "qAddDeptHead" may be undefined when you try and use
    it.
    <cfquery name="qAddDeptHead" datasource="#db#"
    result="yourResult">
    SET NOCOUNT ON;
    INSERT INTO Employee ( Columns here )
    VALUES (... values here ...)
    SELECT EmployeeID AS NewEmployeeID
    SET NOCOUNT OFF;
    </cfquery>
    <cfquery name="qNewEmpPosition" datasource="#db#">
    INSERT INTO EmployeePositions(EmployeeID, .... )
    VALUES ( #qAddDeptHead.NewEmployeeID#, ....)
    </cfquery>

  • Regarding ssis - split multi value column into multiple records

    Hi,
    I have one scenario
    Table
    Col1. Col2
    1. A,b,c,df,ghf
    2. C,b
    3. B
    Output should be
    Col1. Col2
    1. A
    1. B
    1. C
    1. Df
    1. Ghf
    2. C
    2. B
    3. B
    please help

    Try the below:
    Create TVF as below:
    CREATE FUNCTION [dbo].[split]
    ( @String NVARCHAR(4000), @Delimiter NCHAR(1) )
    RETURNS TABLE
    AS
    RETURN
    With Split(stpos, endpos)
    AS (
    SELECT 0 AS stpos, CHARINDEX(@Delimiter, @String) AS endpos
    UNION ALL
    SELECT endpos + 1, CHARINDEX(@Delimiter, @String, endpos + 1)
    FROM Split
    WHERE endpos > 0
    SELECT 'Id' = ROW_NUMBER() OVER (ORDER BY (SELECT 1)),
    'Data' = SUBSTRING(@String, stpos, COALESCE(NULLIF(endpos,0), LEN(@String)+1)-stpos)
    FROM Split
    Test script:
    create Table Test_Table(id int, data varchar(4000))
    Insert into Test_Table Values(1,'a,F,c, G'),(2,'LASD,wer,yy')
    Select A.id,upper(Left(b.Data,1)) + lower(Right(b.data, Len(b.data) - 1)) From Test_Table A
    Cross Apply dbo.split(A.data,',') B
    Drop table Test_Table

  • Insert into multiple tables

    Hi experts,
    I would like to consulate if you can recommended on how to build a logic at the entity object. We have two tables or entites A and B and whenever a new record is inserted into table or entity A, a new record will be dependently inserted in table or entity B.
    Can you please advise us on how to code this.

    Ok, now we know that there is a relation, still we don't see what kind of relation.
    Then the next question it's how do you find out off there is a 'parent'?
    Again, provide more detailed information.
    What I can tell you right now it's that I don't see a problem implementing this using ADFbc.
    Timo
    Pss:what kind of ui do you have? 

  • Process to get info from Multiple textboxes and check boxes on a page

    Hi,
    Could you help me with setting up a process which selects the data from multiple textboxes and checkboxes on a page and should be pointing to a single table in the database.
    Thanks in advance,
    Verity.

    Thanks Peter for the reply,
    Actually the problem is, there are lot of check boxes. And process should be like when a user clicks on, say 7 out of 10 checkboxes, only those values needs to be inserted in a table in database. Actually my "insert all" statement is inserting 7 values and also the other three values as null. I tried insert with 'when' and 'if' but didnt get through. my sample insert statement is as follows. Could you help me here.
    DECLARE
    BEGIN
    insert all
    when (:P1_POT='PT') then
    into TABLENAME
    (oid,year, code)
    values
    (:F1_ID, :F1_YEAR, :P1_HR)
    when (:P1_HOL='SC')
    then into TABLENAME
    (OID, year,code)
    values
    (:F1_ID, :F1_YEAR, :P1_SD)
    select oid,year,code from TABLENAME;
    END;

Maybe you are looking for