Update Dataset

nikavak
nikavak used Ask the Experts™
on
I have a project in Vb.net wich works fine. I tried converted to C# and does not work. The problem is while button1 button2 and is clicked. The dsSessionNew never accepts changes. What i am doing wrong? Please help me.
Vb Working VODE:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            'create dataset type dsTest. 
            Dim ds As New dsTest
            'create data table type normal_eventsTableAdapter.
            Dim dt As New dsTestTableAdapters.normal_eventsTableAdapter
            'fill data table with normal_events data.
            dt.Fill(ds.normal_events)
 
            'create new dataset type Dataset.
            Dim ds1 As New DataSet
            'asign dataset ds1 with ds witch contains 3 columns. 
            ds1 = retSpecialGameStatus()
 
            Dim i As Integer
            For i = 0 To ds.Tables(0).Rows.Count - 1
                Dim objDR As System.Data.DataRow
                'create new row.
                objDR = ds1.Tables(0).NewRow
                objDR("nev_home_team") = ds.Tables(0).Rows(i).Item(0).ToString
                objDR("nev_id") = CInt(ds.Tables(0).Rows(i).Item(1).ToString)
                objDR("Bulc") = i
                ds1.Tables(0).Rows.Add(objDR)
 
                ds1.AcceptChanges()
            Next
 
            ASPxGridView1.DataSource = ds1
            ASPxGridView1.DataBind()
 
            Session("Grid") = ds1
 
 
        End If
 
 
    End Sub
    Public Function retSpecialGameStatus() As DataSet
 
        'create dataset type Dataset. 
        Dim ds As New DataSet
        'create datatable type Datatable.
        Dim objDT As System.Data.DataTable
 
        'set name of new datatable.
        objDT = New System.Data.DataTable("RetDataTable")
        'add 3 columns to datable.
        objDT.Columns.Add("nev_home_team", GetType(String))
        objDT.Columns.Add("nev_id", GetType(Integer))
        objDT.Columns.Add("Bulc", GetType(Integer))
 
       
        'add datatable to dataset.
        ds.Tables.Add(objDT)
 
        retSpecialGameStatus = ds
    End Function
    
 
 
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        Session("Grid").Tables(0).Rows(0).Item(2) = 7
        Session("Grid").Tables(0).Rows(3).Item(2) = 7
        Session("Grid").AcceptChanges()
 
        ASPxGridView1.DataSource = Session("Grid")
        ASPxGridView1.DataBind()
 
        Session("Grid") = ASPxGridView1.DataSource
 
    End Sub
 
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
 
        Session("Grid").Tables(0).Rows(1).Item(2) = 5
        Session("Grid").Tables(0).Rows(4).Item(2) = 5
        Session("Grid").AcceptChanges()
 
        ASPxGridView1.DataSource = Session("Grid")
        ASPxGridView1.DataBind()
 
        Session("Grid") = ASPxGridView1.DataSource
    End Sub
 
 
C# Non Working code:
 
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) 
        {
               //create dataset type dsTest.
               DsNev ds = new DsNev();
               //create data table type normal_eventsTableAdapter.
               DsNevTableAdapters.normal_eventsTableAdapter dt = 
                            new DsNevTableAdapters.normal_eventsTableAdapter();
               //fill data table with normal_events data.
               dt.Fill(ds.normal_events);
            
               //create new dataset type Dataset.
               DataSet ds1 = new DataSet();
               //asign dataset ds1 with ds witch contains 4 columns.
               ds1 = retSpecialGameStatus();
              
               int i = 0;
               for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) {
                   DataRow objDR;
                   //create new row.
                   objDR = ds1.Tables[0].NewRow();
                   objDR["nev_id"] = int.Parse(ds.Tables[0].Rows[i].ItemArray[0].ToString());
                   objDR["nev_visitor_team"] = ds.Tables[0].Rows[i].ItemArray[1].ToString();
                   objDR["nev_home_team"] = ds.Tables[0].Rows[i].ItemArray[2].ToString();
                   objDR["Bulc"] = i;
                   ds1.Tables[0].Rows.Add(objDR);
                 
                   ds1.AcceptChanges();
               }
              
               ASPxGridView1.DataSource = ds1;
              ASPxGridView1.DataBind();
              
                  
               Session["Grid"] = ds1;
           }
 
 
    }
    public DataSet retSpecialGameStatus()
    {
 
        //create dataset type Dataset.
        DataSet ds = new DataSet();
        //create datatable type Datatable.
        DataTable objDT;
 
        //set name of new datatable.
        objDT = new DataTable("RetDataTable");
        //add 4 columns to datable.
        objDT.Columns.Add("nev_id", typeof(int));
        objDT.Columns.Add("nev_home_team", typeof(string));        
        objDT.Columns.Add("nev_visitor_team", typeof(string));
        objDT.Columns.Add("Bulc", typeof(int));
 
 
        //add datatable to dataset.
        ds.Tables.Add(objDT);
 
        return ds;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        DataSet dsSessionNew = new DataSet();
        dsSessionNew = (DataSet)Session["Grid"];       
 
 
        dsSessionNew.Tables[0].Rows[0].ItemArray[3] = 7;
        dsSessionNew.Tables[0].Rows[3].ItemArray[3] = 7;     
        
 
        dsSessionNew.AcceptChanges();
 
        ASPxGridView1.DataSource = Session["Grid"];
        ASPxGridView1.DataBind();
 
 
        Session["Grid"] = ASPxGridView1.DataSource;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet dsSessionNew1 = new DataSet();
 
        dsSessionNew1 = (DataSet)Session["Grid"];
 
        dsSessionNew1.Tables[0].Rows[1].ItemArray[3] = 5;
        dsSessionNew1.Tables[0].Rows[4].ItemArray[3] = 5;
        dsSessionNew1.AcceptChanges();
 
        ASPxGridView1.DataSource = Session["Grid"];
        ASPxGridView1.DataBind();
 
        Session["Grid"] = ASPxGridView1.DataSource;
    }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Is the Button1_Click event actually happening?

If not, try adding the following line at line 93 of your code:

                Button1.Click +=Button1_Click;

Dabas

Author

Commented:
You did not understand, the problem is about dataset. It does not accept changes.
Ok.

So I understand that you are sure that Button1_Click is happening but your dataset is not accepting changes.
How do you know it isn't?

Also, if I look at your line 180, you are setting the DataSource to Session["Grid"]. Have you tried changing that line to

ASPxGridView1.DataSource = dsSessionNew1

Dabas

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial