CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Threaded View

  1. #1
    Join Date
    May 2008
    Posts
    7

    UpdateCommand vs. InsertCommand

    Using .NET v. 1.1.

    Why is it, that using UpdateCommand i am able to add rows to a table, but the process is painfully slow. When trying to use InsertCommand, i get a strange error {"ERROR [07002] COUNT field incorrect" }, though there isn't such field in the DataSet/Table.

    Soo, this code works:
    Code:
    public void UpdateData(SelectConn i_enConn, DataSet i_dsTmp, string i_strTable)
        {
          OdbcCommandBuilder CommandBuilder = null; 
          OdbcDataAdapter daAdapter = null; 
          OdbcConnection connConnection = null; 
          OdbcTransaction trans = null;
          
          try {
            try {
              switch (i_enConn) {
                case SelectConn.From :
                  connConnection = m_connFrom;
                  break;
    
                case SelectConn.To :
                  connConnection = m_connTo;
                  break;
              } 
            }
            catch (System.Exception exx) {
              string foobar = exx.Message.Trim();
              connConnection = null;
            }
    
            if (connConnection != null) {
              trans = connConnection.BeginTransaction(IsolationLevel.Serializable); 
              daAdapter = new OdbcDataAdapter();
              OdbcCommand cmd1 = new OdbcCommand("SELECT * FROM " + i_strTable, connConnection, trans);
              daAdapter.SelectCommand = cmd1;
              CommandBuilder = new OdbcCommandBuilder(daAdapter); 
    
              daAdapter.UpdateCommand = CommandBuilder.GetUpdateCommand();
              
              OdbcCommand cmd2 = new OdbcCommand(daAdapter.UpdateCommand.CommandText, connConnection, trans);
              
              daAdapter.UpdateCommand = cmd2;
              daAdapter.Update(i_dsTmp);  
              trans.Commit();
            } 
          }
          catch (System.Exception ex) {
            throw ex;
          }
        }
    But this one doesn't:
    Code:
    public void UpdateData(SelectConn i_enConn, DataSet i_dsTmp, string i_strTable)
        {
          OdbcCommandBuilder CommandBuilder = null; 
          OdbcDataAdapter daAdapter = null; 
          OdbcConnection connConnection = null; 
          OdbcTransaction trans = null;
          
          try {
            try {
              switch (i_enConn) {
                case SelectConn.From :
                  connConnection = m_connFrom;
                  break;
    
                case SelectConn.To :
                  connConnection = m_connTo;
                  break;
              } 
            }
            catch (System.Exception exx) {
              string foobar = exx.Message.Trim();
              connConnection = null;
            }
    
            if (connConnection != null) {
              trans = connConnection.BeginTransaction(IsolationLevel.Serializable); 
              daAdapter = new OdbcDataAdapter();
              OdbcCommand cmd1 = new OdbcCommand("SELECT * FROM " + i_strTable, connConnection, trans);
              daAdapter.SelectCommand = cmd1;
              CommandBuilder = new OdbcCommandBuilder(daAdapter); 
    
              daAdapter.InsertCommand = CommandBuilder.GetInsertCommand();
              OdbcCommand cmd2 = new OdbcCommand(daAdapter.InsertCommand.CommandText, connConnection, trans);
              daAdapter.InsertCommand = cmd2;
              daAdapter.Update(i_dsTmp);  //{"ERROR [07002] COUNT field incorrect" }
              trans.Commit();
            } 
          }
          catch (System.Exception ex) {
            throw ex;
          }
        }
    Last edited by cokelite; May 14th, 2008 at 06:14 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured