S
steroche
I would REALLY appreciate help please please please! Im sure it is
probably blindingly obvious to most of you but I am totally in the dark
here!I am lost - i thought i had finally figured out this dataSet
updating lark when i realised that i think i am right back at square
1!!!
Here's my scenario - i have a SQLDB and i retrieve all my data from
that into a dataset and display this to a datagrid(WebForm). I have got
this grid sorted and paged and all but i cannot update records. When i
try I always get the error "There is no row at position" x. Do i need
to create a DataTable when i create the dataset? I thought i could
handle everything through the dataset?? If so how do i go about doing
this???Do i have to somewhow cast all the rows from the dataset or
what?
Can somebody please help?? Code to follow:
public void fillperson()
{
mySQLConnection sqlConn = new mySQLConnection();
sqlComm_person = new SqlCommand();
sqlComm_person.Connection = sqlConn.GetConnection();
sqlComm_person.CommandText = "proc_getpersonDetailswithName";
sqlComm_person.CommandType = CommandType.StoredProcedure;
SqlDataAdapter daperson = new SqlDataAdapter(sqlComm_person);
sqlConn.GetConnection().Open();
daperson.Fill(dsperson, "person");
dsperson.Tables[0].TableName = "person";
Cache["personData"] = dsperson;
Session["personData"] = dsperson;
sqlConn.GetConnection().Close();
}
private void BindData(DataGrid dg, string name)
{
// Bind the dsperson source
dg.DataSource = (DataSet) Cache[name];
dg.DataSource = (DataSet) Session[name];
// Bind the data
dg.DataBind();
}
private void dgperson_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string personid, newOrderID,newLname,newCompanyID,newnotes,newArea =
null;
string Order_ID,Company_ID,notes,Current_Area,person_ID = null;
TextBox tb;
tb =
(TextBox)(dgperson.Items[dgperson.EditItemIndex].FindControl("txtEditperson_ID"));
personid = tb.Text;
tb =
(TextBox)(dgperson.Items[dgperson.EditItemIndex].FindControl("txtEditOrder"));
newOrderID = tb.Text;
tb =
(TextBox)(dgperson.Items[dgperson.EditItemIndex].FindControl("txtEditCompany"));
newCompanyID = tb.Text;
tb =
(TextBox)(dgperson.Items[dgperson.EditItemIndex].FindControl("txtEditnotes"));
newnotes = tb.Text;
tb =
(TextBox)(dgperson.Items[dgperson.EditItemIndex].FindControl("txtEditArea"));
newArea = tb.Text;
mySQLConnection sqlConn = new mySQLConnection();
sqlComm_Updateperson = new SqlCommand();
sqlComm_Updateperson.Connection = sqlConn.GetConnection();
sqlComm_Updateperson.CommandText =
"proc_personUpdateCommand_restrict";
sqlComm_Updateperson.CommandType = CommandType.StoredProcedure;
//all stored procedure go in here - these are all ok i think
//
SqlDataAdapter daUpdateperson = new
SqlDataAdapter(sqlComm_Updateperson);
daUpdateperson.Fill(dsperson, "person");
int count = 0;
count = dsperson.Tables[0].Rows.Count;
Cache["personData"] = dsperson;
Session["personData"] = dsperson;
this.dsperson.Tables["person"].Rows[e.Item.ItemIndex][2] =
newOrderID;
this.dsperson.Tables["person"].Rows[e.Item.ItemIndex][3] =
newCompanyID;
this.dsperson.Tables["person"].Rows[e.Item.ItemIndex][4] = newnotes;
this.dsperson.Tables["person"].Rows[e.Item.ItemIndex][5] = newArea;
this.daperson.Update(dsperson, "person");
dgperson.EditItemIndex = -1;
// Refreshes the grid
BindData(this.dgperson, "personData");
}
Can somebody please tell me where i am going wrong???
If theres some syntactical errors they are probably a mistake when
posting as i had to change my column names for privacy.
Thanks
Steve
probably blindingly obvious to most of you but I am totally in the dark
here!I am lost - i thought i had finally figured out this dataSet
updating lark when i realised that i think i am right back at square
1!!!
Here's my scenario - i have a SQLDB and i retrieve all my data from
that into a dataset and display this to a datagrid(WebForm). I have got
this grid sorted and paged and all but i cannot update records. When i
try I always get the error "There is no row at position" x. Do i need
to create a DataTable when i create the dataset? I thought i could
handle everything through the dataset?? If so how do i go about doing
this???Do i have to somewhow cast all the rows from the dataset or
what?
Can somebody please help?? Code to follow:
public void fillperson()
{
mySQLConnection sqlConn = new mySQLConnection();
sqlComm_person = new SqlCommand();
sqlComm_person.Connection = sqlConn.GetConnection();
sqlComm_person.CommandText = "proc_getpersonDetailswithName";
sqlComm_person.CommandType = CommandType.StoredProcedure;
SqlDataAdapter daperson = new SqlDataAdapter(sqlComm_person);
sqlConn.GetConnection().Open();
daperson.Fill(dsperson, "person");
dsperson.Tables[0].TableName = "person";
Cache["personData"] = dsperson;
Session["personData"] = dsperson;
sqlConn.GetConnection().Close();
}
private void BindData(DataGrid dg, string name)
{
// Bind the dsperson source
dg.DataSource = (DataSet) Cache[name];
dg.DataSource = (DataSet) Session[name];
// Bind the data
dg.DataBind();
}
private void dgperson_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string personid, newOrderID,newLname,newCompanyID,newnotes,newArea =
null;
string Order_ID,Company_ID,notes,Current_Area,person_ID = null;
TextBox tb;
tb =
(TextBox)(dgperson.Items[dgperson.EditItemIndex].FindControl("txtEditperson_ID"));
personid = tb.Text;
tb =
(TextBox)(dgperson.Items[dgperson.EditItemIndex].FindControl("txtEditOrder"));
newOrderID = tb.Text;
tb =
(TextBox)(dgperson.Items[dgperson.EditItemIndex].FindControl("txtEditCompany"));
newCompanyID = tb.Text;
tb =
(TextBox)(dgperson.Items[dgperson.EditItemIndex].FindControl("txtEditnotes"));
newnotes = tb.Text;
tb =
(TextBox)(dgperson.Items[dgperson.EditItemIndex].FindControl("txtEditArea"));
newArea = tb.Text;
mySQLConnection sqlConn = new mySQLConnection();
sqlComm_Updateperson = new SqlCommand();
sqlComm_Updateperson.Connection = sqlConn.GetConnection();
sqlComm_Updateperson.CommandText =
"proc_personUpdateCommand_restrict";
sqlComm_Updateperson.CommandType = CommandType.StoredProcedure;
//all stored procedure go in here - these are all ok i think
//
SqlDataAdapter daUpdateperson = new
SqlDataAdapter(sqlComm_Updateperson);
daUpdateperson.Fill(dsperson, "person");
int count = 0;
count = dsperson.Tables[0].Rows.Count;
Cache["personData"] = dsperson;
Session["personData"] = dsperson;
this.dsperson.Tables["person"].Rows[e.Item.ItemIndex][2] =
newOrderID;
this.dsperson.Tables["person"].Rows[e.Item.ItemIndex][3] =
newCompanyID;
this.dsperson.Tables["person"].Rows[e.Item.ItemIndex][4] = newnotes;
this.dsperson.Tables["person"].Rows[e.Item.ItemIndex][5] = newArea;
this.daperson.Update(dsperson, "person");
dgperson.EditItemIndex = -1;
// Refreshes the grid
BindData(this.dgperson, "personData");
}
Can somebody please tell me where i am going wrong???
If theres some syntactical errors they are probably a mistake when
posting as i had to change my column names for privacy.
Thanks
Steve