Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2003, 11:44 AM
Authorized User
 
Join Date: Aug 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rosalynb
Default Auto_Identity column read in another table

I have a Table which has a column works as“auto_identity”
I want to point to the last value of this column and then in another table read the value of that.
SQL1 = "insert into Table1 values (" + Lnum + ", 'REFER' , '" + Dt + "', '" + RunDt.ToString() + "', @@IDENTITY )";
conn.Execute(SQL1, out returnRecords, 0);


int i = 1;
foreach (string s in split)
         {

SQL2 = "insert into Table2 values ('read the value of the identity column', " + i + ", '" + s + "')";
conn.Execute(SQL2, out returnRecords, 0);
    ++i;
         }
would you help pls

thanks

My code is in C#.
__________________
--------------------
Thanks
Rose
[email protected]
 
Old September 17th, 2003, 05:29 PM
Authorized User
 
Join Date: Aug 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rosalynb
Default

Oh God noone answered!!!!!!!!!!
here is the task that I got the great result by that.

public int Execute(string stringSQL, bool bGetIdent)
    {
        // open connection if it is closed.
        if (conn.State == System.Data.ConnectionState.Closed)
            conn.Open();
        // Build a connection and SQL strings
        string SQL;
        if (bGetIdent)
        {
            SQL = "SET NOCOUNT ON;\n";
            SQL += stringSQL + ";\n";
            SQL += "SELECT @@IDENTITY AS Ident;\n";
            SQL += "SET NOCOUNT OFF;\n";
        }
        else SQL = stringSQL;
        // Create command object
        Microsoft.Data.Odbc.OdbcCommand cmd = new Microsoft.Data.Odbc.OdbcCommand(SQL);
        cmd.Connection = conn;
        // Call command's ExecuteScalar
        int returnID = 0;
        object returnObject = cmd.ExecuteScalar();
        if (bGetIdent)
            if (returnObject != null)
                returnID = System.Convert.ToInt32(returnObject.ToString());
        return returnID;
    }

hope it helps ...





Similar Threads
Thread Thread Starter Forum Replies Last Post
I can read one table but the other not??? Why rtr1900 Classic ASP Databases 2 February 26th, 2007 10:50 AM
Read-Only Linked Table pjm Access VBA 2 December 1st, 2006 03:37 PM
Read-Only Linked Table pjm Access 6 August 21st, 2006 07:42 AM
how to make column of table 1 = to column of table gilgalbiblewheel Classic ASP Databases 4 October 11th, 2004 11:57 PM
Q:Read two rows from table LegoMan ASP.NET 1.0 and 1.1 Basics 4 October 14th, 2003 01:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.