SQLITE and dataGridView1
本文关键字:dataGridView1 and SQLITE | 更新日期: 2023-09-27 18:22:40
我搜索并购买我找不到解决方案这是我的代码
private void pointage_Load(object sender, EventArgs e)
{
sql = "SELECT firstname, lastname FROM company";
command = new SQLiteCommand(sql, connectiondb);
DataSet1 mydata = new DataSet1();
SQLiteDataAdapter zz = new SQLiteDataAdapter(sql, connectiondb);
zz.Fill(mydata.Tables["DataTable1"]);
int i;
SQLiteDataReader reader = command.ExecuteReader();
DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[1].Clone();
while (reader.Read())
{
for (i = 0; i <= System.Convert.ToUInt32(reader["id"]); i++)
{
row = this.dataGridView1.Rows[i];
row.Cells["Column10"].Value = reader["firstname"].ToString();
row.Cells["Column9"].Value = reader["lastname"].ToString();
}
}
}
如果我离开这条线路,我需要做什么
row = this.dataGridView1.Rows[i];
row.Cells["Column10"].Value = reader["firstname"].ToString();
row.Cells["Column9"].Value = reader["lastname"].ToString();
我只放了
MessageBox.Show(reader["firstname"].ToString());
这会起作用,但当我做时
for (i = 0; i <= System.Convert.ToUInt32(reader["id"]); i++)
{
row = this.dataGridView1.Rows[i];
row.Cells["Column10"].Value = reader["firstname"].ToString();
row.Cells["Column9"].Value = reader["lastname"].ToString();
}
不起作用:'(
有什么不好的,请帮我
好了,伙计们,我终于找到了解决方案:D
while (reader.Read())
{
i = System.Convert.ToInt32(reader["id"].ToString());
dataGridView1.Rows.Add();
MessageBox.Show(System.Convert.ToString(i));
DataGridViewRow R = dataGridView1.Rows[i-1];
R.Cells["Column9"].Value = reader["firstname"].ToString();
R.Cells["Column10"].Value = reader["lastname"].ToString();
}