数据显示
private void Netonlin_Load(object sender, EventArgs e)
{
string cstr = "select ID as '编号',Ysong as '歌曲名称',Yauthor as '歌手',Ytype as '歌曲类型',Ytime as '总时长',Yname as '歌曲热榜' from Listdate";
c.BindDataGridView(dataGridView1, cstr);
dataGridView1.Columns[0].Width = 40;
dataGridView1.Columns[1].Width = 80;
treeView1.ImageIndex = 0;//设置图像列表的索引
treeView1.SelectedImageIndex = 0;//设置选中节点时显示的图像列表索引
string str1 = "select count(*) from Listdate";
toolStripStatusLabel2.Text = c.HumanNum(str1).ToString() + "首歌";
TreeNode tn = treeView1.Nodes.Add("所有热歌榜");//添加节点
SqlConnection conn = DBConnection.MyConnection();
conn.Open();
SqlCommand cmd = new SqlCommand("select * from Model", conn);
SqlDataReader dpr = cmd.ExecuteReader();
while (dpr.Read())
{
tn.Nodes.Add(dpr["Yname"].ToString());
}
dpr.Close();
conn.Close();
treeView1.ExpandAll();
}
public void BindDataGridView(DataGridView dgv, string sql)
{
SqlDataAdapter sda = new SqlDataAdapter(sql, conn); //创建数据适配器对象
DataSet ds = new DataSet(); //创建数据集对象
sda.Fill(ds); //填充数据集
dgv.DataSource = ds.Tables[0]; //绑定到数据表
ds.Dispose(); //释放资源
}
当在load事件时,弹出不了窗体,why