.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Datatable Merge Mystery

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :ASP.Net
Hi,I have three datatables that I'm trying to merge. Each has it's own data source, which is an Excel worksheet. Each worksheet contains two columns, each containing String values. Each datatable fills fine, but when I carry out the merge the first column from two of the datatables disappears!As part of my debugging I'm outputting data to the console in order to see what is going on. As each table is filled I iterate through the rows and can see that each datatable has two columns which are filled with the data that I would expect. I see that each table has two columns (datatable.columns.count) and that each column has a datatype of string.I have created a master datatable, into which the data is merged. Once the merge has taken place, I again iterate through the rows, just as I did with the individual tables. The master datatable has two columns, each of datatype string. I can see that the first merge has worked. All of the data from the source datatable appears in the master datatable. However, after the second and third merge I can see that the first column of data is missing. That is to say that the first column of data from my second and third datatable does not appear in the master datatable. I just have blank values.Some of the rows in my original worksheets contain blank rows. This of course means that there are some blank rows in my datatables. I'm not

View Complete Post

More Related Resource Links

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

DataTable - Load from IDataReader - CreateDataReader - ReadXml WriteXml - Free ADO.NET Tutorials

The DataTable in ADO.NET 2.0 has been seriously beefed up and I absolutely love it. Not everything we consume deals with multiple resultsets and requires the ever popular DataSet. With the cool new features in the ADO.NET 2.0 DataTable, we can get many of the cool features in the DataSet without all the extra baggage and memory footprint particular to multiple resultsets.

Load DataTable from IDataReader

Datatable in session


I am creating a simple shopping cart using a datatable that is passed into a session object.  I have a small mini cart that displays the total number of items in the cart as well as the running total - this is displayed in a web control.  When the web control starts up I run a try/catch to see if the session object exists, if it doesn't I create the datatable for the cart and store it in the session.  I then have a datalist control that contains all the information for my products including an "add to cart" button.  When the page loads everything looks fine.  If I click on an "add to cart" button nothing happens to the session information.  If I click on it again, the session information updates - displaying only one item is in the cart and then counts up correctly there after.  Additionally, after adding an item, if I select a different item in the list, the same issue occurs.  I am not sure why this is happeing, if anyone can give me an idea I would appreciate it. 

holding datatable value using session



iam insert record using datable in gridivew,iam using  session to hold the record,

there is any other way to hold the record in datable.


        DataRow row;
        row = dtempty.NewRow();
        row["ratetypeid"] = ddlratetype.SelectedValue;
        row["ratedesc"] = ddlratetype.SelectedItem.Text;
        row["slabs"] = ddlslabs.SelectedValue;   

removing item from datatable


hi to all ..thanks in advance


I have Two datatables dtA,dtB ,both contains column name is "FiledName" I need to remove item

from dtA when same row data exists in dtB.  please tell me how to do it

dtA    dtB   

 A        A

 B        F

 C        C

 D        Z

I want o/p like this







Bulk Copy From Datatable To SQL Server Table


 I have read the data of a excle file and captured the data into the dataset to a datatable, now that data is to be inserted into a SQL Server table using bulk copy option. I am using -

 public bool BulkEnterData(DataTable dt, string tblName)
        SqlBulkCopy bulk = new SqlBulkCopy(con);
        bulk.DestinationTableName = tblName;

        return true;

ERROR Getting-
A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The pipe has been ended.) 

How to resolve the above problem or any other solution is available.


While Importing Excel 2007 file to Datatable - headerrow problem


Hi there,


I am trying to simply extract an excel data from an uploaded file an put it into a datatable. In this case the excel file has 3 rows but when I fill the datatable I only see row count of 2.

I tried changing HDR:NO; to HDR:YES and vice versa, but no luck. 

What am I doing wrong? (Note: the excel file cannot have a  headerrow)


string connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pFilePath + ";Extended Properties=\"Excel 12.0;IMEX=1;HDR:NO;\"";
            OleDbConnection conn = new OleDbConnection(connstr);
            DataTable dtTables = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
            string strTablename = dtTables.Rows[0]["TABLE_NAME"].ToString();
            string strSQL = "SELECT * FROM [" + strTablename + "]";

            OleDbCommand cmd = new OleDbCommand(strSQL, conn);

            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            //At this point row count=2 which doesn't make sense




Mail Merge




I am after creating a mail merge documents from datasource and .dot template file on server side. Can you give me an idea how i will achive this?


Thanks in advance.



Syed Hussain



Merge SQL to Excel--Need .Net button to open on fly and have current SQL data!


           Hello all,
I do not know if this is the proper place to ask this, but my question is...
I have a SQL DB and I want to convert it to Excel Sheet (I did this using the wizard)!
In my aspx page I have a button.  So when I press this button I want the Excel sheet to open!  But I need the Excel sheet to show me the up to date information that is in the SQL DB.  

Conversion of List to DataTable and ViceVersa


hi ,

           Iam having a requirement where I wil get datatable or Dataview from the DataAccessLayer I need to convert them into GanaricList of entites and ViceVersa from GenericList to Datatable or DataView.

             I tried it but I cant. Can anybody help me out.

Data Points: DataSet and DataTable in ADO.NET 2.0


ADO. NET 2. 0 sports some exciting enhancements to the core classes found in ADO. NET 1. x and introduces a variety of new classes, all of which promise to improve performance, flexibility, and efficiency.

John Papa

MSDN Magazine November 2005

who to load DataRow to DataTable



Who can I copy data from DataRow[] to DataTable....

DataRow[] TempDataRowFilter;



DataTable TempFilterTable = new DataTable();
TempFilterTable.LoadDataRow(TempDataRowFilter, true);

It is error why ?         

Linq query to DataTable


Is there option to convert from Linq.IQueryable to DataTable with some sort of CopyToDataTable() function. I am trying this.
     var row = from p in dc.ProductModels
                  select p;
    DataTable dt = row.CopyToDataTable();

Is there option to convert from Linq.IQueryable to DataTable with some sort of CopyToDataTable() function. I am trying this.

     var row = from p in dc.ProductModels


How to merge 3 separated color (Red, Green and Blue) saved as grayscale images images into colored i


Hi friends, I have separated Red, Green and Blue color from a bitmap image and stored it in grayscale (obviously).  Now I want to know how can I merge it so that I can get the exact previous colour, when I am merging them by reading its color values but it is giving  me grayscale image :( . Please help me out with some working sample code. Thanking in anticipation.

I am using the following code:

 public bool mergeToRGBandWriteBitmap(string sourceRFile, string sourceGFile, string sourceBFile, string targetFile)
            bool isSuccessfullywritten = false;
                Bitmap bitmapRed = (Bitmap)Image.FromFile(sourceRFile);
                Bitmap bitmapGreen = (Bitmap)Image.FromFile(sourceGFile);
                Bitmap bitmapBlue = (Bitmap)Image.FromFile(sourceBFile);
   Bitmap afterMerge = mergeRGB(bitmapRed, bitmapGreen

DataTable --> Oracle DB



Can someone offer advice on the below? 

I am connecting to an AR Server and pulling out data into a DataSet.  There will be 15 different DataTables within the set.  I would like to find a way to either insert the entire DataSet or each DataTable into an Oracle table.  The Oracle table has the same format as the DataTables I'm creating.

 private void button1_Click(object sender, EventArgs e)
                //Get Credentials
                ID = userNameTextBox.Text;
                PW = passWordTextBox.Text;

                connString = gstrConnectBaseLineStart + "UID=" + ID + ";PWD=" + PW + gstrConnectBaseLineEnd; //Connection string
                conn = new OdbcConnection(connString); //Create Connection
                conn.Open(); //Open Connection
                Console.Write("Connection Successful" + "\n");

                dataAdapter = new OdbcDataAdapter(SQL, conn);
                dataAdapter.Fill(IncidentsDataSet, "dataTableTest");

                DataTable dataTable = new DataTable();
                dataTable = IncidentsDataSet.Tables["dataTableTest"];

                dataGridView1.DataSource = dataTable;

                //Would like to create som

merge word document



I recently created a team site on the SharePoint for projects management and our team will use the word document for inserting the information about the project that they work on it,

My case is:

for each project have multiple documents and i created a user control by VS.2005, this user control contain a drop down list contain all projects and merge button, when the user choose any project and click merge i will use the Work dll to merge all document that related to the project and export to the user.

This is my code

private void mergeDocument()


ApplicationClass WordApp =

datatable select from ddl


I have a datatable with 3 columns: id, AdGrp, Desc.  I bind it to a drop downlist that has id as the selected value and AdGrp as the selected text. I also have a label that i would like to display the Desc column value when ever the ddl selected index changes.  I was thinking of using  a select on the datatable with the selected value but not sure how i to do that.  Here is the code i have so far:

 string filter = "Id={0}";

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend