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

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

Update a datatable with another one

Posted By:      Posted Date: August 30, 2010    Points: 0   Category :ASP.Net
Hi Friends,                    I want to merge two datatables(say dtsource and dttarget)..I have a key solumn for each of the datatable..If key of dtsource equals key of dttarget, i want to update dttarget withy rows from dtsource..otherwise(keys are not equal) ,i want to insert rows from dtsource to dttarget..How it is possible?..pls give me the simplest solution in C# to do this                   For eg,dtsource have two columns XID,X and dttarget have YID,Y...And i want to add the rows of XID and X under the columns YID and Y..if XID equals YID..I want to update the value of YID and Y with the value of XID and X...

View Complete Post

More Related Resource Links

How to save and update the contents in a datatable

Hi, I am having problem in updating the contents of my datatable in datagrid. When i run the program and edit the contents of the rows in my datatable they remain there, but when i close the program and run it once more they are set back to their original predefined contents. Please tell me that how can i save the edits made at runtime in my datatable. This is the code for my program. Please review it first: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;   namespace WindowsFormsApplication5 {     public partial class Form1 : System.Windows.Forms.Form     {         private System.ComponentModel.Container components;         private Button button1;         private Button button2;         private DataGrid myDataGrid;         private DataSet myDataSet;         private bool TablesAlreadyAdded;         public Form1()         {             // Required for Windows Form Designer support.             InitializeComponent();        &n

DataTable to update database

tbl.Columns.Add("COL1"); Hi all!Is it possible to construct a DataTable by yourself i.e. specify the column names and populate the data rows, and then update the back-end database?I am sending a list of objects of a same class to a DataTable:1. Lets say my class is :class step{int COL1;String COL2;int COL3;}2. I am sending an ArrayList of  above objects to a DataTablepublic DataTable GenTable(ArrayList listStep){DataTable tbl  = new DataTable();tbl.Columns.Add("COL1",i32);tbl.Columns.Add("COL2",String);tbl.Columns.Add("COL3",i32); }Now, finally, I need to update the back-end SQL Server database. How do I update that?thanks,Nick

Adding rows to a databound DataSet/DataTable from a ThreadPool thread does not update UI


I have an WPF .NET 4.0 application which creates a TreeView in the main thread, and databinds it to a DataSet which contains two DataTables. The datatables have a simple relationship between them which represents a two-level tree. When the treeview is initially drawn, it correctly displays all items from the two datatables as a two level tree.

When the DataTables are updated from the UI thread (add/delete/modify a row), the treeview is refreshed and the changes to the databound DataSet DataTables are visible in the treeview.

If changes to the DataTables are made from a ThreadPool thread, no exceptions are thrown, but the UI is not updated. I am using a threadpool thread because the changes will be initiated from multiple network devices and processing their data is fairly CPU intensive.

I am assuming that change notifications are not being propogated across threads for DataSets/DataTables.  Is this assumption correct? If so, are their recommended best practices to overcome this limitation?

ASP.Net Gridview Edit Update Cancel Commands

In ASP.Net 2.0, GridView Control also provides the functionality to edit and update the data retrieved from the database using CommandField template. You can cancel the action using Cancel Command of the CommandField. GridView consists of events that can be used to perform the actions like edit, update and cancel upon the Data items displayed in the ASP.Net GridView Data Control.

How to format and update GridView and DataGrid rows using JQuery

The behavior described in this question is as expected. When you set text of a cell in grid, it directly affects HTML that is going to be rendered. When you set text value of a cell, it means that you are setting innerText of the cell. The column that GridView creates for command fields (Edit, Delete and Select) are a (anchor) or button elements. So you can see what will happen if you set text value in that cell. It will wipe out those link or button controls and replace them with simple text string.

Update Vs SystemUpdate

Many of you might noticed that share point ListItem has Update() method as well as SystemUpdate().

What is the difference between these two methods and why MOSS has two different APIs for updating an ListItem

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

SqlCommand.ExecuteNonQuery() returns -1 when doing Insert / Update / Delete

Sometimes you end up with a return value of -1 when using the SqlClient.SqlCommand.ExecuteNonQuery method.

Why is that?

Well, the ExecuteNonQuery method is there for statements for changing data, ie. DELETE / UPDATE /INSERT, and the returned value are the number of rows affected by that statement.

When checking the documentation we can see that there are some conditions that return -1.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.

When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of

rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

>>>How to update multiple rows of gidview by one click



I want to add multiple rows of a gridview if the data for multiple fields are same.

Idea for this is that a user may search a record with some parameter e.g. Sector, plot.

For example 15 records being displayed in gridview.

There should be checkbox before every row and if user wants to update Plot and Flat No that is same for 10 rows out of 15 so he will check the rows and update.

For this a dialog box should appear asking for the parameter i.e. Plot and Flat or something else next time may be it will be City or country. Moreover, there is already an Edit button to update records, when user click it another page open for the record to be updated and whatever he wants to update, it updates.

Hope everone understand the scenario.

I don't want to disturb the already provided Edit functionality and want to provide same record to be updated.

Any idea in this regard would be appreciated.

Visual Studio closes itself by opening aspx-Page designer after Windows Update


Hey Guys,

I've a problem with my Visual Studio.

On the 13th of August 2010 i installed a Windows update on my vista sp2 pc. For this date my Visual Studio 2008 sp 1 always has closed itself by opening an aspx-page in designer view. There is no error message just closing the window. I restored a backup of my windows from the time before updating it and it helped, i could open aspx pages in the design view till the update has been installed again automatically after rebooting the pc. I can't disable windows updates, cause it's my pc at work and safety is very important. I hope you could help me out of this disaster.



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;   

Update net frame 3.5.


I use visual studio 2008 but It's only use net frame work 2.0, Can I update and use net frame work 3.5 for Visual Studio 2008 ? Please help me !


update/delete not working on server only


my aspx page works in VWD, and everything works on the server EXCEPT update and delete sql functions. any ideas?


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.


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