Update unable to find TableMapping['Table'] or DataTable 'Table' in c# sqlserver

Discussion in 'Software' started by Nishanth, Nov 9, 2009.

  1. Nishanth

    Nishanth

    Joined:
    Nov 9, 2009
    Messages:
    1
    Hi i am trying to update my sql server table with dataAdapter.Update('datasetname')

    Here i am getting the exception: " Update unable to find TableMapping['Table'] or DataTable 'Table' ".

    My C# code is as follows :

    public int SaveSalesDetails(Int64 customerId,Int64 appTypeId,string purchaseOrderNo,float VAT,string modifiedBy,string vehicleNo,float lessAmount,float totalAmount,int paymentStatus,
    int modeOfPayment, float cashAmount, string chequeNo, string bank, string chequeDate, float chequeAmount, DataSet dsItems)
    {
    SqlTransaction trans = null;
    int retVal = 0;
    Int64 newSalesInvoiceNo=0;
    DataSet dsItemsNew;
    DataTable dtItemsNew;
    try
    {
    connection = new SqlConnection(ConfigurationManager.AppSettings.Get("conString"));
    connection.Open();
    trans = connection.BeginTransaction();

    //insert into tblSales table
    string sql = " INSERT INTO tblSales (nCustomerId,nAppTypeId,vPurchaseOrder,fVAT,dSaleDate,vModifiedBy,dModifiedDate,vVehicleNumber,fLess,fTotal,nPaymentStatus,nModeOfPayment,CashAmount,ChequeNo,Bank,CheckDate,ChequeAmount) VALUES";
    sql += "(" + customerId + "," + appTypeId + ",'" + purchaseOrderNo + "'," + VAT + ",'" + DateTime.Today.Date + "' , '" + modifiedBy + "','" + DateTime.Today.Date + "' ,'" + vehicleNo + "'," + lessAmount + "," + totalAmount + "," + paymentStatus + "," + modeOfPayment + "," + cashAmount + ",'" + chequeNo + "','" + bank + "','" + chequeDate + "','" + chequeAmount + "') ;";
    sql += " SELECT SCOPE_IDENTITY()";

    command = new SqlCommand(sql, connection);
    command.Transaction = trans;
    newSalesInvoiceNo = Convert.ToInt64(command.ExecuteScalar());

    if (newSalesInvoiceNo > 0)
    {

    //insert into Kesbro_tblSalesDetails table

    //create new column for sales invoice number
    int rown = dsItems.Tables[0].Rows.Count;
    dtItemsNew = dsItems.Tables[0].Copy();
    int chk2 = dtItemsNew.Rows.Count;
    string check1 = dtItemsNew.Rows[0]["vSerialNumber"].ToString();


    DataColumn dtcol1= new DataColumn("vSalesInvoiceNumber",Type.GetType("System.Int64"));
    dtItemsNew.Columns.Add(dtcol1);

    foreach (DataRow row in dtItemsNew.Rows)
    {
    row["vSalesInvoiceNumber"] = newSalesInvoiceNo;
    }
    dtItemsNew.AcceptChanges();

    dsItemsNew = new DataSet();
    dsItemsNew.Tables.Add(dtItemsNew);


    //do dataset insert into tblSalesDetails table
    dataAdapter = new SqlDataAdapter(command);
    string sqlcmdTxt = "INSERT INTO tblSalesDetails(vSalesInvoiceNumber,nBatteryId,vSerialNumber,fUnitPrice,nQuantity,fAmount) VALUES "+
    "(@vSalesInvoiceNumber,@nBatteryId,@vSerialNumber,@fUnitPrice,@nQuantity,@fAmount )";

    dataAdapter.InsertCommand = new SqlCommand(sqlcmdTxt, connection);

    dataAdapter.InsertCommand.Parameters.Add("@vSalesInvoiceNumber", SqlDbType.BigInt, 0, "vSalesInvoiceNumber");
    dataAdapter.InsertCommand.Parameters.Add("@nBatteryId", SqlDbType.BigInt, 0, "nBatteryId");
    dataAdapter.InsertCommand.Parameters.Add("@vSerialNumber", SqlDbType.BigInt, 0, "vSerialNumber");
    dataAdapter.InsertCommand.Parameters.Add("@fUnitPrice", SqlDbType.BigInt, 0, "fUnitPrice");
    dataAdapter.InsertCommand.Parameters.Add("@nQuantity", SqlDbType.BigInt, 0, "nQuantity");
    dataAdapter.InsertCommand.Parameters.Add("@fAmount", SqlDbType.BigInt, 0, "fAmount");

    int ret = dataAdapter.Update(dsItemsNew);
    if (ret > 0)
    {
    retVal = 1;
    }
    }

    trans.Commit();

    return retVal;
    }
    catch (Exception ex)
    {
    trans.Rollback();
    return 0;
    }
    }



    Here the exception is comming while esxcecuting the line
    " int ret = dataAdapter.Update(dsItemsNew); " before that line every thing ws fine.


    Somebody pls help. Very Urgent
    Last edited: Nov 9, 2009
    Nishanth, Nov 9, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kwgchoy@hotmail.com

    Re: PIX ans SQLServer database

    kwgchoy@hotmail.com, Mar 1, 2005, in forum: Cisco
    Replies:
    5
    Views:
    401
    kwgchoy@hotmail.com
    Mar 1, 2005
  2. Michael G

    Dynamic updating a SqlServer db to a MY Sql DB

    Michael G, Sep 10, 2003, in forum: Computer Support
    Replies:
    0
    Views:
    389
    Michael G
    Sep 10, 2003
  3. Peter

    SQLServer

    Peter, Jul 24, 2004, in forum: Computer Support
    Replies:
    1
    Views:
    2,814
    Duane Arnold
    Jul 24, 2004
  4. gogaterpn

    JSF Datatable rowindex issue

    gogaterpn, Mar 11, 2009, in forum: Software
    Replies:
    0
    Views:
    1,684
    gogaterpn
    Mar 11, 2009
  5. Mark W

    Which SQLServer for 78-702?

    Mark W, Oct 7, 2009, in forum: MCTS
    Replies:
    2
    Views:
    2,223
    jgohil
    Mar 2, 2010
Loading...

Share This Page