I have Gridview (gridview1), some TextEdits in the Form and add some Data's to few rows and i stored the gridview1 Data's and textedits to Access Database. In another form i Bind some column to gridview1 and TextEdits to new Gridview (gridview2). Now if i click edit button on any row in the gridview2, I want to get the Data's from Access Database and shown in 1st Form gridview1 and textedits fill automatically recording to Focused Row cell unique value.
Using this code i get value to TextEdits Fields
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Srihari/OrionSystem.accdb");
OleDbCommand da = new OleDbCommand("select * from invoice_top where invoice_number=" + textEdit5.Text, con);
con.Open();
OleDbDataReader reader = da.ExecuteReader();
while (reader.Read())
{
textEdit12.Text = reader.GetValue(1).ToString();
textEdit13.Text = reader.GetValue(2).ToString();
textEdit4.Text = reader.GetString(3);
dateEdit1.Text = reader.GetValue(8).ToString();
textEdit1.Text = reader.GetValue(5).ToString();
textEdit2.Text = reader.GetValue(6).ToString();
textEdit3.Text = reader.GetValue(7).ToString();
checkEdit1.Checked = reader.GetBoolean(4);
}
con.Close();
I also want to fill gridview Data's ? I tried this bus its not working
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[2], reader1.GetString(2));
How to set Access Database values to grdiview ?? Please Help me ?
Thanks in Advance.
I think you need to read a tutorial on Data Binding.
The GridControl can be bound to a data source which implements IList<>, IBindingList<> or IQueryable<> simply by setting the GridControl.DataSource property. There is no need to loop through your recordset and set the value for each row/cell individually. Additionally, I would suggest you Data Bind your TextEdit controls (to the EditValue property, NOT the Text property) rather than manually setting them like you are doing above.
This code is VB.NET but the ideea is the same in C#
Dim SIRCON as string = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Srihari/OrionSystem.accdb"
Using con As New OleDbConnection(SIRCON)
con.Open()
Dim strSQL As String = "select * from invoice_top where invoice_number=" + textEdit5.Text
dim dt as new datatable
dt.Load(New OleDbCommand(strSQL, conexiune).ExecuteReader())
conexiune.Close()
GridControl1.datasource = dt
GridControl1.ForceInitialise
End Using
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.