[英]How to get the values from Access Database and set in Gridview in C# winforms Devexpress?
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. 我有Gridview(gridview1),在窗体中有一些TextEdits,并将一些数据添加到几行中,我将gridview1数据和textedits存储到Access数据库中。 In another form i Bind some column to gridview1 and TextEdits to new Gridview (gridview2).
在另一种形式中,我将某些列绑定到gridview1并将TextEdits绑定到新的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.
现在,如果我在gridview2中的任何行上单击“编辑”按钮,我想从Access数据库中获取数据并显示在第一个表单gridview1中,并且textedits将自动记录为“聚焦行”单元格唯一值。
Using this code i get value to TextEdits Fields 使用此代码,我获得了TextEdits字段的价值
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 ? 我也想填充gridview数据的? 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 ?? 如何将Access数据库值设置为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. 只需设置GridControl.DataSource属性,即可将GridControl绑定到实现IList <>,IBindingList <>或IQueryable <>的数据源。 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.
此外,我建议您将TextEdit控件数据绑定(到EditValue属性,而不是Text属性),而不是像上面那样手动设置它们。
This code is VB.NET but the ideea is the same in C# 这段代码是VB.NET,但思想在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.