string TableName = "EmpDat"; DataTable orgTable = new DataTable(); orgTable.TableName=TableName; orgTable.Columns.Add("EmpName", typeof(string)); orgTable.Columns.Add("Desig", typeof(string)); orgTable.Columns.Add("EmpFname", typeof(string)); orgTable.Columns.Add("Salary", typeof(int)); orgTable.Columns.Add("Sex", typeof(string)); orgTable.Columns.Add("Branch", typeof(string)); DataRow dr = orgTable.NewRow(); dr["EmpName"] = "Jack"; dr["Desig"] = "Chawki Daar"; dr["EmpFname"] = "Khain The"; dr["Salary"] = 12; dr["Sex"] = "H"; dr["Branch"] = "Not Allowed"; orgTable.Rows.Add(dr); SqlTransaction tran; SqlConnection con = new SqlConnection("Constr"); con.Open(); tran = con.BeginTransaction(); SqlCommand cmd = new SqlCommand("select * from EmpDetail", con); cmd.Transaction = tran; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds,"EmpDat"); DataRow[] dr1 = ds.Tables[0].Select("empname='Jack'"); dr1[0]["empName"] = "Good Morning"; orgTable.AcceptChanges(); DataTable f = orgTable.GetChanges(DataRowState.Modified); // con.Open(); SqlCommandBuilder sqlcmdBuild = new SqlCommandBuilder(da); da.Update(ds.Tables[0]);
try { //Your code here; } Catch(Exeception ex) { //commit your SqlTransaction here; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)