如何在数据库的列表视图中显示数据? [英] How to show data in listview from database?
问题描述
亲爱的人们
如何在数据库的列表视图中显示数据.到目前为止,我所做的是.这是我的代码...
Dear People
How can I display data in listview from database. What I have done so far is. Here is my code...
public partial class DtposMDIParentSystem : Form
{
List<object[]> result = new List<object[]>();
public DtposMDIParentSystem()
{
InitializeComponent();
//create the database connection
OleDbConnection aConnection = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\AP_AE\Desktop\DTPOS_APP\DataBase\DtposDatabase.accdb;");
//create the command object and store the sql query
OleDbCommand aCommand = new OleDbCommand("SELECT * FROM Food", aConnection);
try
{
aConnection.Open();
//create the datareader object to connect to table
OleDbDataReader reader = aCommand.ExecuteReader();
int i = 0;
while (reader.Read())
{
result.Add(new Object[reader.FieldCount]);
reader.GetValues(result[i]);
}
reader.Close();
aConnection.Close();
}
catch (InvalidOperationException ex)
{
MessageBox.Show("Invalid Masseage = " + ex.Message);
}
}
private void cmdOlives_Click(object sender, EventArgs e)
{
if (result.Count > 0)
{
string temp = "";
for (int i = 0; i < result[1].Length; i++)
{
temp += result[1][i] + " ";
}
TableOrderListView.Items.Add(temp);
}
}
}
我的问题是,当我单击cmdOlives_Click事件按钮时,我想在列表视图中显示它,例如:
-----------------------------
编号名称价格
-----------------------------
1颗橄榄3.95
-----------------------------
任何帮助都将非常非常好...
在此先感谢
亲切的问候
Agron
My question is when I click cmdOlives_Click event button I want to display in my listview such as:
-----------------------------
Num Name Price
-----------------------------
1 Olives 3.95
-----------------------------
Any help would be very very greatfull...
Thanks in advance
Kind regards
Agron
推荐答案
在这里 ^ ]
我听不懂您的问题
但只要试试这个
ListViewItem是在ListView控件中添加项目的更好方法.
首先,在各自的ListViewItem控件中添加Item和Suuitems,添加后,只需将listViewItem添加到ListView Control中即可,如
I can not understand your problem
but just try this
ListViewItem is the better way for adding items in ListView controls.
First add Item and Suuitems in the respective ListViewItem Control after the adding you just add listViewItem to ListView Control like,
ListViewItem listViewItem;
listViewItem.Item.Add("....");
listView.SubItems.Add("....");
....
....
TableOrderListView.Items.Add(listViewItem);
这篇关于如何在数据库的列表视图中显示数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!