Insert Data using SqlCommandBuilder in ADO.NET using C#


Unknown | 05:53 |

Insert Data using SqlCommandBuilder in ADO.NET using C#


SqlCommandBuilder: This enables you to UPDATE database tables without having to write the commands, reducing the likelihood of errors. This class cannot be inherited.
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection newConnection = new
SqlConnection
(@"Data Source=R4R-3EFD13BB468\SQLEXPRESS;
initial catalog=newDatabase;integrated security=true;"
);
protected void Page_Load(object sender, EventArgs e)
{
newConnection.Open();
SqlDataAdapter ad = new SqlDataAdapter("select * from emp_tbl", newConnection);
SqlCommandBuilder cmd = new SqlCommandBuilder(ad);
DataSet ds = new DataSet();
ad.Fill(ds);
DataRow MyRow = ds.Tables[0].NewRow();
MyRow["emp_id"] = 1234;
MyRow["emp_name"] = "Anjali";
MyRow["emp_age"] = "25";
ds.Tables[0].Rows.Add(MyRow);
ad.Update(ds);
}
}

Out Put:

3 comments:

{ rmouniak } at: 6 August 2018 at 03:00 said...


This blog gives very important info about .Net Thanks for sharing


Dot Net Online Course Bangalore

{ gowthunan } at: 30 October 2018 at 04:50 said...

That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article.
industrial safety courses in chennai

{ Revathi } at: 5 August 2020 at 23:01 said...

This is most informative and also this post most user friendly and super navigation to all posts.thanks lot!!

android training in chennai

android online training in chennai

android training in bangalore

android training in hyderabad

android Training in coimbatore

android training

android online training

Post a Comment