Click here to Skip to main content
15,917,481 members
Home / Discussions / Database
   

Database

 
QuestionT- SQL Inner Select Pin
Greeky16-Feb-06 1:21
Greeky16-Feb-06 1:21 
AnswerRe: T- SQL Inner Select Pin
Colin Angus Mackay16-Feb-06 2:16
Colin Angus Mackay16-Feb-06 2:16 
QuestionUML modeling Pin
Klempie15-Feb-06 23:57
Klempie15-Feb-06 23:57 
AnswerRe: UML modeling Pin
Juan Pedro Prez16-Feb-06 2:05
Juan Pedro Prez16-Feb-06 2:05 
GeneralRe: UML modeling Pin
Paul Conrad16-Feb-06 17:14
professionalPaul Conrad16-Feb-06 17:14 
AnswerRe: UML modeling Pin
Klempie16-Feb-06 19:25
Klempie16-Feb-06 19:25 
QuestionHelp with ADO.NET, please Pin
Juan Pedro Prez15-Feb-06 23:20
Juan Pedro Prez15-Feb-06 23:20 
AnswerRe: Help with ADO.NET, please Pin
Mike Ellison16-Feb-06 8:04
Mike Ellison16-Feb-06 8:04 
Hi Juan. I wish my Spanish were as good as your English.

My initial question is why are you manipulating rows in an in-memory dataset, rather than just INSERTing a row in the database in TableA, then INSERTing related rows in TableB? Upon inserting the row in Table A, you can retrieve the newly created AutoNumber, by issuing a SELECT @@Identity.

Here's a (very raw, but complete) example of what I mean (in C#):
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Page Language="C#" %>

<script runat="server">
  void btnSubmit_Click(object o, EventArgs e)
  {
    // provide a connection string to the database
    const string kCONNECT_STRING = 
      "Provider=Microsoft.Jet.OLEDB.4.0; "
      + @"Data Source=c:\inetpub\wwwroot\tests\test.mdb";
    
    // provide the insert statement, with @parameters
    const string kINSERT_STATEMENT = 
      "INSERT INTO [MyTable] ([E-Name], [E-Email]) " 
      + " Values (@pName , @pEmail) ";
    
    OleDbConnection con = null;
    OleDbCommand cmd = null;  
    OleDbParameter pName = null; 
    OleDbParameter pEmail = null; 
    int insertedID = -1;
    
    try
    {
      // get the connection
      con = new OleDbConnection(kCONNECT_STRING);
      con.Open();
      
      // create the insert command
      cmd = new OleDbCommand(kINSERT_STATEMENT, con);
      
      // add parameter values
      pName = new OleDbParameter("@pName", DbType.String);
      pName.Value = tbName.Text;
      cmd.Parameters.Add(pName);
      
      pEmail = new OleDbParameter("@pEmail", DbType.String);
      pEmail.Value = tbEmail.Text;
      cmd.Parameters.Add(pEmail);
      
      // execute the insert command
      cmd.ExecuteNonQuery();
      
      // retrieve the autonumber that was just inserted
      cmd.CommandText = "SELECT @@Identity";
      cmd.CommandType = CommandType.Text;
      cmd.Parameters.Clear();
      insertedID = (int)cmd.ExecuteScalar();

      
      // if we're still here there's been no exceptions;
      // display a message
      Response.Write(
        string.Format("Record has been inserted and assigned ID# {0}."
                      ,insertedID) );
      
    }
    catch (Exception x)
    {
      // on an error, display a message
      Response.Write("There has been an error.  ");
      Response.Write(x.Message);
    }
    finally
    {
      // dispose objects
      if (cmd != null) cmd.Dispose();
      if (con != null) con.Dispose();      
    }
      
  }    
</script>

<html>
  <head>
  </head>
  
  <body>
    <form runat="server">
      <h3>Insert into Access</h3>
      <table>
        <tr>
            <td>Name</td>
            <td><asp:TextBox id="tbName" runat="server" /></td>
        </tr>
        <tr>
            <td>Email</td>
            <td><asp:TextBox id="tbEmail" runat="server" /></td>
        </tr>
      </table>
      <asp:Button id="btnSubmit" runat="server" text="Insert"
                  onclick="btnSubmit_Click" />
    </form>
  </body>
  
</html>

GeneralRe: Help with ADO.NET, please Pin
Juan Pedro Prez17-Feb-06 6:06
Juan Pedro Prez17-Feb-06 6:06 
GeneralRe: Help with ADO.NET, please Pin
Mike Ellison17-Feb-06 6:32
Mike Ellison17-Feb-06 6:32 
GeneralRe: Help with ADO.NET, please Pin
Juan Pedro Prez17-Feb-06 7:46
Juan Pedro Prez17-Feb-06 7:46 
QuestionHow to get record count from OledbDataReader? Pin
rushing15-Feb-06 23:00
rushing15-Feb-06 23:00 
AnswerRe: How to get record count from OledbDataReader? Pin
Colin Angus Mackay16-Feb-06 2:11
Colin Angus Mackay16-Feb-06 2:11 
GeneralRe: How to get record count from OledbDataReader? Pin
rushing16-Feb-06 17:04
rushing16-Feb-06 17:04 
QuestionAdventure Works Database Pin
Brendan Vogt15-Feb-06 22:56
Brendan Vogt15-Feb-06 22:56 
AnswerRe: Adventure Works Database Pin
Colin Angus Mackay16-Feb-06 2:24
Colin Angus Mackay16-Feb-06 2:24 
QuestionGood ADO/ SQL Server 2005 Books Pin
Brendan Vogt15-Feb-06 20:57
Brendan Vogt15-Feb-06 20:57 
QuestionSQL Log viewer Pin
devvvy15-Feb-06 20:52
devvvy15-Feb-06 20:52 
QuestionSQL 2005 MSDN connections Pin
Tad McClellan15-Feb-06 17:51
professionalTad McClellan15-Feb-06 17:51 
AnswerRe: SQL 2005 MSDN connections Pin
Paul Conrad15-Feb-06 19:10
professionalPaul Conrad15-Feb-06 19:10 
QuestionNo SQL Server Management Tools Pin
Brendan Vogt14-Feb-06 23:40
Brendan Vogt14-Feb-06 23:40 
AnswerRe: No SQL Server Management Tools Pin
Colin Angus Mackay15-Feb-06 0:38
Colin Angus Mackay15-Feb-06 0:38 
QuestionRe: No SQL Server Management Tools Pin
Brendan Vogt15-Feb-06 1:02
Brendan Vogt15-Feb-06 1:02 
AnswerRe: No SQL Server Management Tools Pin
Colin Angus Mackay15-Feb-06 1:07
Colin Angus Mackay15-Feb-06 1:07 
QuestionUrjent SQL Exception Problem Pin
cbhkenshin14-Feb-06 21:20
cbhkenshin14-Feb-06 21:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.