none
Error: The data source does not support server-side data paging.

    Question

  • Hi,
    This is my first time i'm here. I am beginner in program development. I need help from those know this problem.
     I want to build simple program to Insert data to table. When click the Add button the data suppose to insert to table and grid view will display all the data on that table.My problem is with this gridview.My program doesn't display the data from the table in the grid view. Below is my failure program. Please help me.

    ***********************************************************************************************************
    protected void bnAdd_Click(object sender, EventArgs e)
        {
            SqlCommand cmdO;
     
            string SQL;
            SQL = "Insert into Owner (OID,OName,Race,ContactNumb)" +
                "values(@pOID,@pOName,@pRace,@pContactNumb)";
            conn.Open();
            grdO.Visible = true;
            cmdO = new SqlCommand(SQL, conn);
            cmdO.Parameters.AddWithValue("pOID",Convert.ToString(txtID.Text));
            cmdO.Parameters.AddWithValue("pOName",txtName.Text);
            cmdO.Parameters.AddWithValue("pRace",txtRace.Text);
            cmdO.Parameters.AddWithValue("pContactNumb",txtNumb.Text);
            cmdO.ExecuteNonQuery();
            conn = null;
            SQL = null;
            //for grid view
            SqlDataAdapter daO;
            DataSet dsO;
            //get detail of owner
            SQL = "Select OID,OName,Race,ContactNumb from Owner";
            daO = new SqlDataAdapter(SQL, conn);
            dsO = new DataSet();
            daO.Fill(dsO, "Owner");
            grdO.Visible = true;
            grdO.DataSource = dsO;
            grdO.DataMember = "Owner";
            grdO.DataBind();
            dsO = null;
            daO = null;
            conn.Close();

     
        }


    Wednesday, March 05, 2008 4:47 AM

Answers

All replies

  • The problem is that you have not initialized your connection. As I see from the code you assign null to conn variable so when you call Fill method it throws an exception.
    Wednesday, March 05, 2008 7:32 AM
  • Hi GD thanks for ur comment...
    I've found solution to do my program but I've found another problem. It's about paging. I want to do page for the grid view so the  list will not be so long.
    Here I put my new program.

    The error is like this
     The data source does not support server-side data paging.

    I put in bold the indicate error:
    grdO.DataBind();



    please help
    ************************************

    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class InsertToGridView : System.Web.UI.Page
    {
        public SqlConnection conn = new SqlConnection("Data Source=ZUHAI;Database=MyHome;" +
            "Integrated Security=True");
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                grdO.Visible = true;
            }
        }
        protected void bnAdd_Click(object sender, EventArgs e)
        {
            SqlCommand cmdO;
            string SQL;
            SQL = "Insert into Owner (OID,OName,Race,ContactNumb)" +
                "values(@pOID,@pOName,@pRace,@pContactNumb)";
            conn.Open();
            cmdO = new SqlCommand(SQL, conn);
            cmdO.Parameters.AddWithValue("pOID",Convert.ToString(txtID.Text));
            cmdO.Parameters.AddWithValue("pOName",txtName.Text);
            cmdO.Parameters.AddWithValue("pRace",txtRace.Text);
            cmdO.Parameters.AddWithValue("pContactNumb",txtNumb.Text);
            cmdO.ExecuteNonQuery();
            conn.Close();
            BindData();

        }

        protected void grdO_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
        {
            grdO.PageIndex = e.NewPageIndex;
            BindData(); 
        }

        private void BindData()
        {
            //for grid view
            SqlDataReader drO;
            SqlCommand cmdO;
            string SQL;
            SQL = "Select * from Owner";
            conn.Open();
            cmdO = new SqlCommand(SQL, conn);
            drO = cmdO.ExecuteReader();

            grdO.Visible = true;
            grdO.DataSource = drO;
            grdO.DataBind();
            conn.Close();
        }

    }

    Wednesday, March 05, 2008 9:06 AM
  • Hi Guy,

     

    You are using ASP.Net, right ? This section are all about Windows Form.

    So you can find answer in this forum: 

    http://forums.asp.net/

    Thursday, March 06, 2008 7:18 AM
  • Hi meechada,

    The only change you have to do is in the BindData().
    Here you have used the SqlDataReader to read data retrieved from the database, but SqlDataReader is
    forward only. You can not traverse back and forth on it.
    So the solution for this is using DataAdapter and DataSet.
    So your function may change some what like this -

    private void BindData()
    {
    //for grid view
    SqlCommand cmdO;
    string SQL;
    SQL = "Select * from Owner";
    conn.Open();
    cmdO = new SqlCommand(SQL, conn);

    SqlDataAdapter da = new SqlDataAdapter(
    cmdO);
    DataSet ds = new DataSet();
    da.Fill(ds);
    grdO.Visible = true;
    grdO.DataSource = ds;
    grdO.DataBind();
    ds.Dispose();
    da.Dispose();
    conn.Close();
    }

    This surely works. The rest of your code is fine. Enjoy coding....

    Regards,
    -
    Napster [Parag].
    • Proposed as answer by Awais Mohammad Tuesday, October 22, 2013 6:57 AM
    Thursday, November 20, 2008 7:00 AM
  • grdo.Allowpaging?
    Tuesday, February 22, 2011 10:50 AM
  • Thanks for your detail explanation for differences between datareader and data set with data adapter.

    After that you should do :

    GridView.PageIndex = e.NewPageIndex  ;

    GridView.DataBind();

     

    on PageIndexChanging event of GridView and that it's

    Thursday, August 25, 2011 12:31 PM
  • i was having the same problem ..

    but now i fixed it ..

    can you please ellaborate about sqlreader and its problems with data source ...

    Regards

    Awais Mohammad

    Tuesday, October 22, 2013 6:58 AM