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中显示数据,同时数据库访问慢该怎么解决
@"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中显示数据,同时数据库访问慢该怎么解决
想可以点击表中某数据弹出一个窗口
{
// 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);
}
}
}
private void InitializeListView()
{
// Set the view to show details.
listView1.View = View.Details; // Allow the user to edit item text.
listView1.LabelEdit = true; // Allow the user to rearrange columns.
listView1.AllowColumnReorder = true; // Select the item and subitems when selection is made.
listView1.FullRowSelect = true; // Display grid lines.
listView1.GridLines = true; // Sort the items in the list in ascending order.
listView1.Sorting = SortOrder.Ascending; // Attach Subitems to the ListView
listView1.Columns.Add("Title", 300, HorizontalAlignment.Left);
listView1.Columns.Add("ID", 70, HorizontalAlignment.Left);
listView1.Columns.Add("Price", 70, HorizontalAlignment.Left);
listView1.Columns.Add("Publi-Date", 100, HorizontalAlignment.Left); // The ListViewItemSorter property allows you to specify the
// object that performs the sorting of items in the ListView.
// You can use the ListViewItemSorter property in combination
// with the Sort method to perform custom sorting.
_lvwItemComparer = new ListViewItemComparer();
this.listView1.ListViewItemSorter = _lvwItemComparer;
}
DataGridView.DataSource=ds.table[0];
/// <summary>
/// 双击列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DataGridView_DoubleClick(object sender, EventArgs e)
{ }