Re: datagrid update command

From: abdoly (abdoly_at_yahoo.com)
Date: 06/04/04


Date: Fri, 4 Jun 2004 08:56:14 -0700

sir

according to ur reply i understood that
first: u believe that may be the value already changed but i cant see it for some reasons
i made 3 things to if know that right
-i display it on a textbox on the form b4 updating the dataset
this.textBox1.text=str;
but i always see the old value
-i updated the dataset with the str and i wrote the dataset to xml file
after updating it
this.dataSet11.WriteXml(@"d:\x\x.xml");
and i checked the file and the old value was there.
-i used the debugger to watch str and the same result here
second: i have to update the datasource with the dataset every time i need to update a

record, then why i use a dataset if i will go to the server every transaction
any way i tried to update the datasource as

this.sqlDataAdapter1.Update(this.dataSet11,"departments");
and the same result , no change in the old value

my code is below
public void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
                //here i m trying to get the new value
                //entered in the datagrid textbox
                // the problem is str always the old value b4 update
                
                        temp=e.Item.Cells[1].Controls[0] as TextBox; // or temp=

(TextBox)e.Item.Cells[1].Controls[0];
                        
                        String str=temp.Text;
                        //the following line just to make sure
                        // i got the new value, but i didnt got it
                        this.TextBox1.Text=str;

                // here i update the dataset
                        editDr=this.dataSet11.Departments.Rows[e.Item.ItemIndex];
                        editDr.BeginEdit();
                        editDr["deptid"]=1;
                        editDr["deptname"]=str;
                        editDr.EndEdit();
                        this.dataSet11.WriteXml(@"d:\x\x.xml");
                        this.sqlDataAdapter1.Update(this.dataSet11,"departments");
                        this.Cache["ds"]=this.dataSet11;
                        this.DataGrid1.EditItemIndex=-1;
                        this.DataGrid1.DataBind();
}

     
     ----- John Saunders wrote: -----
     
     "abdullah" <abdoly@yahoo.com> wrote in message
     news:DA8A3330-BAB5-41DD-BAEC-BE3686D6F5F6@microsoft.com...
>>> ----- John Saunders wrote: -----
>> "abdoly" <abdoly@yahoo.com> wrote in message
> news:CA79A763-B884-44C4-8104-5E60BA526EE8@microsoft.com...
>> hi sir
>> my whole code to update is :
>> public void DataGrid1_UpdateCommand(object
> source,System.Web.UI.WebControls.DataGridCommandEventArgs e)
>> {
>> temp=(TextBox)e.Item.Cells[1].Controls[0];
>> String str=temp.Text;
>> this.TextBox1.Text=str;
>> editDr=this.dataSet11.Departments.Rows[e.Item.ItemIndex];
>> editDr.BeginEdit();
>> editDr["deptname"]=str;
>> editDr.EndEdit();
>> this.Cache["ds"]=this.dataSet11;
>> this.DataGrid1.EditItemIndex=-1;
>> this.DataGrid1.DataBind();
>> }
>> im using (TextBox) casting because another problem wich is using
     CType
> always cause error says that CType is not defined inmy namespace, i
     tried to
> find its base class but i couldnt
>> any way my problem is str always the old value before user update,i
     think
> that has nothing to do with updating the dataset
>> because in all cases i will update it with the old value again
>> I don't see where you updated the database, only the in-memory
     dataset. Have
> you confirmed what the value of "str" is immediately after it is set?
>> Also, CType didn't work because it's a VB.NET thing. You are correct
     to use
> (TextBox) in C#.
> --
> John Saunders
> johnwsaundersiii at hotmail
>> i m sure that there is misunderstanding here
> how can i update the database or the dataset without knowing the value
     to update with
> first i need to know the new value to update my dataset
> look,i press the edit link in the datagrid , a textbox contains the value
     i want to update appears in the cell
> then i have to write the new value in the textbox then press update link
> in the update event i m supposed to get the value wrote in the datagrid
     text box and update the dataset with it
> my problem is i dont know how to get this value,
> another thing, suppose that i dont want to update that value to the
     database i just want to display it in a label on the web
> form, how can i get it to display it
> sorry about my week english and ur time
     
     What I meant is that, given the way you described the problem, it could be
     the case that you thought you were updating the database, but no data
     changed, or that you had looked at the value of "str" in the debugger and
     seen that it hadn't changed. I noticed that the code you provided did not
     update the database, so it could have been the first problem. You didn't say
     how you had seen the value of "str", so it could have been the second
     problem as well.
     --
     John Saunders
     johnwsaundersiii at hotmail
     
     
     



Relevant Pages

  • Re: Looping through a datagrid
    ... updating of the data when the request is posted back to the server. ... This is my> first attempt at creating a working Datagrid and having it update to a> database. ... I have> made some fields in the grid editable and want those changes to hit the> database at the same time with an update button that I have at the bottom of> the grid. ... >> Why would you loop through a data grid? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Please help with a serious issue
    ... be located for updating) they are both invoicing customers that are right ... are updating as well as the previous and next record as sort of a buffer i ... run to a local database and update each night to the server. ... record on a second try because the lock will be removed by the time the user has ...
    (borland.public.delphi.database.ado)
  • Re: Index now option Windows search 4.0
    ... it's database of files on local hard-drives is incomplete for some reason. ... 'magnifying glass' icon in the taskbar? ... time to complete it's updating, until it was complete it too would be ... is this 'Windows Live Desktop Search' that you're ...
    (microsoft.public.windowsxp.general)
  • Re: Unable to update view in Sql Server 2000
    ... > and database-sql server 2000). ... > party component but I don't think the component is the problem. ... > happening is that I'm updating fields that are part of view. ... So it seems that something in the production database ...
    (comp.databases.ms-sqlserver)
  • Re: FileStream , Stream
    ... > image data from database and display on a web form.i have written the ... > what is difference between FileStream, ...
    (microsoft.public.dotnet.framework.aspnet)

Loading