using CommandBuilder insert datat in form datatable in datadase — ADO.Net , C Sharp — ASP.Net Example
ASP.Net Example-using CommandBuilder insert datat in form datatable in datadase

Thursday, May 19, 2011

using CommandBuilder insert datat in form datatable in datadase

This is the best and optimize way of insert data in to database table 
with ado.net
InsertingDataUsingCommandBuilder
using System;
using System.Data;
using System.Data.SqlClient;

public class InsertingDataUsingCommandBuilder
{
 
static void Main(string[] args)
 {
string Cn="DataSource=(local);InitialCatalog=CaseManager;Integrated Security=true";
string Query="SELECT ID, Contact, Email FROM Test";
SqlConnection objConnection = new SqlConnection(Cn);
SqlDataAdapter objDataAdapter = new SqlDataAdapter(Query,objConnection);
SqlCommandBuilder objCmd = new SqlCommandBuilder(objDataAdapter);
DataSet objDataSet = new DataSet();
objDataAdapter.Fill(objDataSet);
DataRow objRow = objDataSet.Tables[0].NewRow();
objRow["ID"] = 520;
objRow["Contact"] = "Bill";
objRow["Email"] = "Ray";
objDataSet.Tables[0].Rows.Add(objRow);
objDataAdapter.Update(objDataSet);
        }
    }

1 comment:

ASPdotNET-Example