07-06-2015, 10:50
|
|
|
חבר מתאריך: 03.03.15
הודעות: 7
|
|
הצגת נתונים בדתהגריד
הקוד הזה הוא לשליפת נתונים והצגתם בדתהגריד.
הנתונים נשלפים אך הוא לא מציג אותם בדתה גריד
//create the connection string
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Directory.GetCurrentDirectory() + "\\YokraBaor.mdb";
//create the database query
string query = "SELECT * FROM tblHazmanot";
//create an OleDbDataAdapter to execute the query
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
//create a command builder
OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
//create a DataTable to hold the query results
DataTable dTable = new DataTable();
//fill the DataTable
dAdapter.Fill(dTable);
//the DataGridView
//BindingSource to sync DataTable and DataGridView
BindingSource bSource = new BindingSource();
//set the BindingSource DataSource
bSource.DataSource = dTable;
for (int i = 0; i <= dTable.Rows.Count - 1; i++)
{
//dataGridView1.Rows[i].Cells[0].Value =dTable.Rows[i].ItemArray[0];
//dataGridView1.Rows[i].Cells[1].Value=dTable.Rows[i].ItemArray[1];
//dataGridView1.Rows[i].Cells[2].Value = dTable.Rows[i].ItemArray[2];
//dataGridView1.Rows[i].Cells[3].Value = dTable.Rows[i].ItemArray[3].ToString();
//dataGridView1.Rows[i].Cells[4].Value = dTable.Rows[i].ItemArray[4].ToString();
//dataGridView1.Rows[i].Cells[5].Value = dTable.Rows[i].ItemArray[5].ToString();
//dataGridView1.Rows[i].Cells[6].Value = dTable.Rows[i].ItemArray[6].ToString();
//dataGridView1.Rows[i].Cells[7].Value = dTable.Rows[i].ItemArray[7].ToString();
}
//set the DataGridView DataSource
dataGridView1.DataSource = bSource;
מהי הסבה לדעתכם?
|