//加载
private void button2_Click_1(object sender, EventArgs e)
{
listView1.Items.Clear();
listView1.Columns.Clear();
SqlConnection con = new SqlConnection("server=.;database=t5;user id=sa;password=123");
con.Open();
DataSet dst = new DataSet();
SqlCommand cmd = new SqlCommand("select ID,Format,Cotegory,Place,Star,Name,director,Price,Number from AaA", con);
SqlDataAdapter dap = new SqlDataAdapter(cmd);
dap.Fill(dst);
con.Close();
this.listView1.Columns.Add("ID编号", 80, HorizontalAlignment.Center);
this.listView1.Columns.Add("格式", 80, HorizontalAlignment.Center);//增加列标题
this.listView1.Columns.Add("类型", 80, HorizontalAlignment.Center);
this.listView1.Columns.Add("产地", 80, HorizontalAlignment.Center);//增加列标题
this.listView1.Columns.Add("主演", 80, HorizontalAlignment.Center);
this.listView1.Columns.Add("音像名称", 80, HorizontalAlignment.Center);//增加列标题
this.listView1.Columns.Add("导演", 80, HorizontalAlignment.Center);
this.listView1.Columns.Add("价格", 80, HorizontalAlignment.Center);//增加列标题
this.listView1.Columns.Add("库存数量", 80, HorizontalAlignment.Center);
listView1.View = View.Details;
listView1.GridLines = true;//显示网格线。。
string[] str = new string[9];
foreach (DataRow row in dst.Tables[0].Rows)
{
str[0] = row["ID"].ToString();
str[1] = row["Format"].ToString();
str[2] = row["Cotegory"].ToString();
str[3] = row["Place"].ToString();
str[4] = row["Star"].ToString();
str[5] = row["Name"].ToString();
str[6] = row["director"].ToString();
str[7] = row["Price"].ToString();
str[8] = row["Number"].ToString();
ListViewItem item = new ListViewItem(str, 0);
listView1.Items.Add(item);
}