Skip to content
Loading
  • +1
    Did you try to debug and identify which line is giving error?
    +1
  • Nigel Fernandes
    0
    I'm assuming you are using ASP.Net gridview
     
    You will need to enable paging and handle paging events in your code behind file.
    0
  • 0
    Thanks for posting the code..
     
    It's lot of code. Can you tells us at which line in the code you are getting the error?
     
    There are lot of "Table[0]" can you mention at which line you are seeing error "table[0]"?
     
    The error occurs in the Form_Load ? 
    On which button click the error occurs?
    0
  • 0
    Hi,
     
    Is you issue resolved.
     
    I could run your code on my local machine without any error.
     
    Let me know if you are still facing any error. Let me know what which line of code you are seeing error. 
    0
  • Nigel Fernandes
    0
    Hi you cannot access
    ds.Tables[0].  from another function in a web application.
     
    Web applications are different from windows applications.
    If you need that data again, either re query it from the database OR save the ds in a session variable . Saving in the session variable is not a good practice. 
    0
  • -1
    Please find below my full code that gave me the error of table[0] cannot be found:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using MySql.Data.MySqlClient;
    namespace IMAN_ISTFDatabase
    {
    public partial class Members : Form
    {
    public Members()
    {
    InitializeComponent();
    }
    private void Members_Load(object sender, EventArgs e)
    {
    MySqlConnection con = new MySqlConnection(ConnectionString);
    con.Open();
    da = new MySqlDataAdapter("select * from members", con);
    MySqlCommandBuilder builder = new MySqlCommandBuilder(da);
    ds = new DataSet();
    da.Fill(ds, "members");
    membersDataGridView.DataSource = ds.Tables["members"];
    }
    MySqlDataAdapter da;
    DataSet ds;
    int i = 0;
    string ConnectionString = "datasource=localhost;port=3306;username=root;password=natforce123";
    private void btnFirst_Click(object sender, EventArgs e)
    {
    if (ds.Tables[0].Rows.Count > 0)
    {
    i = 0;
    iDCardNoTextBox.Text = ds.Tables[0].Rows[i]["IDCardNo"].ToString();
    firstNameTextBox.Text = ds.Tables[0].Rows[i]["Firstname"].ToString();
    lastNameTextBox.Text = ds.Tables[0].Rows[i]["Lastname"].ToString();
    sexComboBox.Text = ds.Tables[0].Rows[i]["Sex"].ToString();
    dateTimePicker1.Text = ds.Tables[0].Rows[i]["DOB"].ToString();
    designationTextBox.Text= ds.Tables[0].Rows[i]["Designation"].ToString();
    dateOfAppointmentDateTimePicker.Text = ds.Tables[0].Rows[i]["AppointmentDate"].ToString();
    dateTimePicker2.Text = ds.Tables[0].Rows[i]["IDIssueDate"].ToString();
    addressTextBox.Text = ds.Tables[0].Rows[i]["Address"].ToString();
    phoneNoTextBox.Text = ds.Tables[0].Rows[i]["PhoneNo"].ToString();
    lGATextBox.Text= ds.Tables[0].Rows[i]["LGA"].ToString();
    stateOfOperationComboBox.Text = ds.Tables[0].Rows[i]["StateOfOperation"].ToString();
    stateOfOriginComboBox.Text = ds.Tables[0].Rows[i]["StateOfOrigin"].ToString();
    memberStatusComboBox.Text = ds.Tables[0].Rows[i]["MemberStatus"].ToString();
    }
    }
    private void btnLast_Click(object sender, EventArgs e)
    {
    i = ds.Tables[0].Rows.Count - 1;
    iDCardNoTextBox.Text = ds.Tables[0].Rows[i]["IDCardNo"].ToString();
    firstNameTextBox.Text = ds.Tables[0].Rows[i]["Firstname"].ToString();
    lastNameTextBox.Text = ds.Tables[0].Rows[i]["Lastname"].ToString();
    sexComboBox.Text = ds.Tables[0].Rows[i]["Sex"].ToString();
    dateTimePicker1.Text = ds.Tables[0].Rows[i]["DOB"].ToString();
    designationTextBox.Text = ds.Tables[0].Rows[i]["Designation"].ToString();
    dateOfAppointmentDateTimePicker.Text = ds.Tables[0].Rows[i]["AppointmentDate"].ToString();
    dateTimePicker2.Text = ds.Tables[0].Rows[i]["IDIssueDate"].ToString();
    addressTextBox.Text = ds.Tables[0].Rows[i]["Address"].ToString();
    phoneNoTextBox.Text = ds.Tables[0].Rows[i]["PhoneNo"].ToString();
    lGATextBox.Text = ds.Tables[0].Rows[i]["LGA"].ToString();
    stateOfOperationComboBox.Text = ds.Tables[0].Rows[i]["StateOfOperation"].ToString();
    stateOfOriginComboBox.Text = ds.Tables[0].Rows[i]["StateOfOrigin"].ToString();
    memberStatusComboBox.Text = ds.Tables[0].Rows[i]["MemberStatus"].ToString();
    }
    }
    private void btnNext_Click(object sender, EventArgs e)
    {
    if (i < ds.Tables[0].Rows.Count - 1)
    {
    i++;
    iDCardNoTextBox.Text = ds.Tables[0].Rows[i]["IDCardNo"].ToString();
    firstNameTextBox.Text = ds.Tables[0].Rows[i]["Firstname"].ToString();
    lastNameTextBox.Text = ds.Tables[0].Rows[i]["Lastname"].ToString();
    sexComboBox.Text = ds.Tables[0].Rows[i]["Sex"].ToString();
    dateTimePicker1.Text = ds.Tables[0].Rows[i]["DOB"].ToString();
    designationTextBox.Text= ds.Tables[0].Rows[i]["Designation"].ToString();
    dateOfAppointmentDateTimePicker.Text = ds.Tables[0].Rows[i]["AppointmentDate"].ToString();
    dateTimePicker2.Text = ds.Tables[0].Rows[i]["IDIssueDate"].ToString();
    addressTextBox.Text = ds.Tables[0].Rows[i]["Address"].ToString();
    phoneNoTextBox.Text = ds.Tables[0].Rows[i]["PhoneNo"].ToString();
    lGATextBox.Text= ds.Tables[0].Rows[i]["LGA"].ToString();
    stateOfOperationComboBox.Text = ds.Tables[0].Rows[i]["StateOfOperation"].ToString();
    stateOfOriginComboBox.Text = ds.Tables[0].Rows[i]["StateOfOrigin"].ToString();
    memberStatusComboBox.Text = ds.Tables[0].Rows[i]["MemberStatus"].ToString();
    }
    else
    {
    }
    }
    private void btnPrevious_Click(object sender, EventArgs e)
    {
    if (i == ds.Tables[0].Rows.Count - 1 || i != 0)
    {
    i--;
    iDCardNoTextBox.Text = ds.Tables[0].Rows[i]["IDCardNo"].ToString();
    firstNameTextBox.Text = ds.Tables[0].Rows[i]["Firstname"].ToString();
    lastNameTextBox.Text = ds.Tables[0].Rows[i]["Lastname"].ToString();
    sexComboBox.Text = ds.Tables[0].Rows[i]["Sex"].ToString();
    dateTimePicker1.Text = ds.Tables[0].Rows[i]["DOB"].ToString();
    designationTextBox.Text = ds.Tables[0].Rows[i]["Designation"].ToString();
    dateOfAppointmentDateTimePicker.Text = ds.Tables[0].Rows[i]["AppointmentDate"].ToString();
    dateTimePicker2.Text = ds.Tables[0].Rows[i]["IDIssueDate"].ToString();
    addressTextBox.Text = ds.Tables[0].Rows[i]["Address"].ToString();
    phoneNoTextBox.Text = ds.Tables[0].Rows[i]["PhoneNo"].ToString();
    lGATextBox.Text = ds.Tables[0].Rows[i]["LGA"].ToString();
    stateOfOperationComboBox.Text = ds.Tables[0].Rows[i]["StateOfOperation"].ToString();
    stateOfOriginComboBox.Text = ds.Tables[0].Rows[i]["StateOfOrigin"].ToString();
    memberStatusComboBox.Text = ds.Tables[0].Rows[i]["MemberStatus"].ToString();
    }
    }
     
    -1
  • -1
    I get the error on each of the button click that is: next, previous, first and last. Or is there a code i need to set?
    -1