I have a check button that will fetch the month and year in combo box:
private void cmdSend_Click(object sender, System.EventArgs e)
{
List<string>[] list;
list = dbConnect.Select(month_list.SelectedItem.ToString(), year_list.SelectedItem.ToString());
printer_info.Rows.Clear();
for (int i = 0; i < list[0].Count; i++)
{
int number = printer_info.Rows.Add();
printer_info.Rows[number].Cells[0].Value = list[0][i];
printer_info.Rows[number].Cells[1].Value = list[1][i];
printer_info.Rows[number].Cells[2].Value = list[2][i];
printer_info.Rows[number].Cells[3].Value = list[3][i];
}
}

The check button then pass the month and year to the select statement function:
public List<string>[] Select(string month,string year)
{
string query = "SELECT * FROM page_counter WHERE month = '@month' AND year = @year;";
//Create a list to store the result
List<string>[] list = new List<string>[4];
list[0] = new List<string>();
list[1] = new List<string>();
list[2] = new List<string>();
list[3] = new List<string>();
//Open connection
if (this.OpenConnection() == true)
{
//Create Command
MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.Parameters.Add("@month",MySqlDbType.VarChar);
cmd.Parameters.Add("@year", MySqlDbType.Year);
cmd.Parameters["@month"].Value = month;
cmd.Parameters["@year"].Value = year;
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();
//Read the data and store them in the list
while (dataReader.Read())
{
list[0].Add(dataReader["id"].ToString() + "");
list[1].Add(dataReader["month"].ToString() + "");
list[2].Add(dataReader["year"].ToString() + "");
list[3].Add(dataReader["page_count"].ToString() + "");
}
//close Data Reader
dataReader.Close();
//close Connection
this.CloseConnection();
//return list to be displayed
return list;
}
the data will then display on the gridview where all column are specified by default in page designer:
When I run the code, it doesnt have any error, but theres no value display on the gridview. Is there any mistake I make? Im newbie in c# winform,please advise.
List<string>[]? use a class with 4 properties instead.