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

Top 5 Contributors of the Month
Lee Hnetinka

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Update Database Table using DataSet

Posted By:Praveen       Posted Date: December 02, 2008    Points: 10    Category: ADO.NET    URL: http://www.dotnetspark.com  

Below is the code to update DataBase tableĀ using DataSet with the help of CommandBuilder Object. Its Simple. SqlDataAdapter.Update() method is been used to Update DataBase in disconnected architecture.

private void UpdateDataBaseWithDataSet()


SqlConnection conn = new SqlConnection("Server=ServerName; Database=DBName; User ID=yourDBUserID; Password=yourDBPassword;");



conn.Open(); //Open Connection

SqlDataAdapter dataAdapter = new SqlDataAdapter();

SqlCommand sqlComnd = new SqlCommand("select * from TestTable", conn);

dataAdapter.SelectCommand = sqlComnd;

SqlCommandBuilder comndBuilder = new SqlCommandBuilder(dataAdapter);

DataSet dataSet = new DataSet();


DataRow dr;

dr = dataSet.Tables[0].Rows[0]; //Extract the row youwant to update

dr["UserName"] = "Any Other Name"; // Set the Column UserName name to any other value



catch (Exception ex)


throw ex;




conn.Close(); //Close SQL Connection



Hope this will helpfull to all the developer who want to update DataBase table using DataSet.

Happy Coding!!!


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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