Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > Update unable to find TableMapping['Table'] or DataTable 'Table' in c# sqlserver

Reply
Thread Tools

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

 
 
Nishanth Nishanth is offline
Junior Member
Join Date: Nov 2009
Posts: 1
 
      11-09-2009
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,dSaleD ate,vModifiedBy,dModifiedDate,vVehicleNumber,fLess ,fTotal,nPaymentStatus,nModeOfPayment,CashAmount,C hequeNo,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("Sys tem.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,vSe rialNumber,fUnitPrice,nQuantity,fAmount) VALUES "+
"(@vSalesInvoiceNumber,@nBatteryId,@vSerialNumber, @fUnitPrice,@nQuantity,@fAmount )";

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

dataAdapter.InsertCommand.Parameters.Add("@vSalesI nvoiceNumber", SqlDbType.BigInt, 0, "vSalesInvoiceNumber");
dataAdapter.InsertCommand.Parameters.Add("@nBatter yId", SqlDbType.BigInt, 0, "nBatteryId");
dataAdapter.InsertCommand.Parameters.Add("@vSerial Number", SqlDbType.BigInt, 0, "vSerialNumber");
dataAdapter.InsertCommand.Parameters.Add("@fUnitPr ice", SqlDbType.BigInt, 0, "fUnitPrice");
dataAdapter.InsertCommand.Parameters.Add("@nQuanti ty", 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 by Nishanth; 11-09-2009 at 10:06 AM..
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort a datatable and create a new datatable Fredrik Rodin ASP .Net 3 09-28-2007 07:28 AM
Upgrading ASP w/SQLserver 2000 to ASP.NET w/ SQLserver 2005 =?Utf-8?B?SmVmZnJleQ==?= ASP .Net 2 04-27-2007 03:33 PM
Update unable to find TableMapping .. or Datatable xaime ASP .Net 1 05-05-2005 12:19 PM
Casting DataTable to class inherit from DataTable =?Utf-8?B?Qmx1ZWZsb3dlcg==?= ASP .Net 0 04-02-2004 05:41 AM
Adding DataTable Rows To another DataTable J. Babe ASP .Net 1 08-15-2003 05:04 PM



Advertisments