Click to See Complete Forum and Search --> : dataset update


soniyakapoor03
March 5th, 2006, 03:24 AM
hi guys,

i have big problem in datagrid updates,

i am binding a datagrid from two tables.
in datagrid i had one check box.
if i checked the the check box i had to pass the information to the database.

on click a button this has to happen


My code is given below
private void btnRoleSelect_Click(object sender, System.EventArgs e)
{
DataSet ds = (DataSet) Session["DataSet"];
DataTable oldDataTable = ds.Tables["Roles"];
DataTable newDataTable = new DataTable();
DataRow dataRow;
SqlDataAdapter Adapter= new SqlDataAdapter();
DataColumn[] userIDColumn = new DataColumn[1];
userIDColumn[0] = (DataColumn) oldDataTable.Columns["RoleID"];
oldDataTable.PrimaryKey = userIDColumn;
foreach(DataGridItem Item in grdRoles.Items)
{
int RoleId = Convert.ToInt32((grdRoles.DataKeys[Item.ItemIndex]));
int UserId=Convert.ToInt32(drpUserName.SelectedItem.Value );

dataRow =oldDataTable.Rows.Find(RoleId);
if (((CheckBox) Item.FindControl("chkRoles")).Checked)
{

dataRow["IsEnable"]=1;
}
else
{
dataRow["IsEnable"]=0;
}







}


if (ds.HasChanges())
{
Adapter.Update( ds,"Roles");
ds.AcceptChanges();
}

grdRoles.DataSource = newDataTable;

grdRoles.DataBind();



}