vb

private void FindFrmMainRecord()
        {
            int i = 0;
            string strsql = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Stkm.mdb;Persist Security Info=False";
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strsql);
            conn.Open();
            if (conn.State == ConnectionState.Open)
            {
                string sql = "select * from stk";
                OleDbCommand com = new OleDbCommand(sql, conn);
                OleDbDataReader read = com.ExecuteReader();
                try
                {
                    while (read.Read())
                    {
                        dataGridView1.Rows.Add();
                       // dataGridView1.Rows[i].Cells[0].Value = i + 1;//"ID""name"]
                        dataGridView1.Rows[i].Cells[0].Value = read[1];
                        dataGridView1.Rows[i].Cells[1].Value = read[3];
                        dataGridView1.Rows[i].Cells[2].Value = read[4];
                        i = i + 1;
                        
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

本文为原创文章,转载请注明出处!