日期:2014-05-18  浏览次数:20959 次

ListView怎么绑定dataset
SqlConnection khc = new SqlConnection(@"Data Source=.\SQLEXPRESS;" +
  @"AttachDbFilename='F:\BFWORK\PROGRAMS\one\database1\LMSystem.mdf';" +
  @"Integrated Security=True;Connect Timeout=30;User Instance=true");
  khc.Open();
  SqlDataAdapter da = new SqlDataAdapter();
  SqlCommand cmd1 = new SqlCommand("SELECT 用户名,用户密码,用户等级 from 用户信息表", khc);
  da.SelectCommand = cmd1;
  DataSet dset = new DataSet();
之后该怎么写可以在listview中显示数据,同时数据库访问慢该怎么解决

------解决方案--------------------
回复等加分
------解决方案--------------------
探讨
用DATAGRIDVIEW该怎么弄
想可以点击表中某数据弹出一个窗口

------解决方案--------------------
private void LoadList()
{
// Get the table from the data set
DataTable dtable = _DataSet.Tables["Titles"];

// Clear the ListView control
listView1.Items.Clear();

// Display items in the ListView control
for (int i = 0; i < dtable.Rows.Count; i++)
{
DataRow drow = dtable.Rows[i];

// Only row that have not been deleted
if (drow.RowState != DataRowState.Deleted)
{
// Define the list items
ListViewItem lvi = new ListViewItem(drow["title"].ToString());
lvi.SubItems.Add (drow["title_id"].ToString());
lvi.SubItems.Add (drow["price"].ToString());
lvi.SubItems.Add (drow["pubdate"].ToString());

// Add the list items to the ListView
listView1.Items.Add(lvi);
}
}
}
------解决方案--------------------
用DataGridView吧,,
DataGridView.DataSource=ds.table[0];
/// <summary>
/// 双击列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DataGridView_DoubleClick(object sender, EventArgs e)
{

}