locked
Count number of row in datasource and show in label failed, help... RRS feed

  • Question

  • User-775831949 posted

    I want to return to label2.text and number of row in datasource. It displays "Label" so the code is not returning number count of row of datasource, something is wrong, please help.... what is wrong with my code ? Thanks

     

      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            AccessDataSource1.DataBind()
           
        End Sub
       
       
        Protected Sub AccessDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)
            Label2.Text = e.AffectedRows.ToString
        End Sub

    Tuesday, June 26, 2012 6:12 AM

Answers

  • User3866881 posted

    Hello:)

    Please make sure that your Datasource is successfully bound to the DataSource. And make sure that your Selected event has been bound to the AccessDatasource.

    If still fails, please use this way instead:

    using(OleDbCommand cmd = new OleDbCommand("select count(*) from xxx",new OleDbConnection("str here"))
    {
        cmd.Connection.Open();
        Response.Write(cmd.ExecuteScalar().ToString());
    }

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 27, 2012 9:27 PM

All replies

  • User1648350404 posted

    Check following:

    http://forums.asp.net/t/967128.aspx/1

    Tuesday, June 26, 2012 6:18 AM
  • User3866881 posted

    Hello:)

    Please make sure that your Datasource is successfully bound to the DataSource. And make sure that your Selected event has been bound to the AccessDatasource.

    If still fails, please use this way instead:

    using(OleDbCommand cmd = new OleDbCommand("select count(*) from xxx",new OleDbConnection("str here"))
    {
        cmd.Connection.Open();
        Response.Write(cmd.ExecuteScalar().ToString());
    }

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 27, 2012 9:27 PM