public partial class Down : Form
{
public Down()
{
InitializeComponent();
get();
} DataSet ds = new DataSet();
SqlDataAdapter da = null;
SqlConnection con = null; public void get()
{
try
{
con = GetCon.getCon();
con.Open();
string sql = "select film_name as '电影名',film_country as '国家',film_date as '日期',film_down as '下载地址' from dianying";
da = new SqlDataAdapter(sql, con);
da.Fill(ds, "Films");
DataGridViewLinkColumn lnk = new DataGridViewLinkColumn();
lnk.Text = "下载";
lnk.Name = "link";
lnk.HeaderText = "下载";
lnk.UseColumnTextForLinkValue = true;
dataGridView1.Columns.Add(lnk);
dataGridView1.DataSource = ds.Tables["Films"];
}
catch
{
MessageBox.Show("绑定失败");
}
finally
{ con.Close();
} } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridView dgv = (DataGridView)sender;
if (dgv.Columns[e.ColumnIndex].Name == "link")
{
string linkStr = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[4].Value.ToString(); try
{
Clipboard.SetText(linkStr);
MessageBox.Show("下载地址已经复制");
}
catch
{
MessageBox.Show("剪切板不能使用");
}
}
} private void button1_Click(object sender, EventArgs e)
{
con = GetCon.getCon();
string text = textBox1.Text.ToString() ;
string sql = "select film_name from dianying where film_name='" + text + "'";
string sql2 = "select film_name as '电影名',film_country as '国家',film_date as '日期',film_down as '下载地址' from dianying where film_name='"+textBox1.Text+"'";
using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
DataSet ds2 = new DataSet();
SqlDataAdapter sda2 = null;
if (sdr.Read())
{
sda2 = new SqlDataAdapter(sql2, con); //已有打开的与此命令相关联的 DataReader,必须首先将它关闭。
sda2.Fill(ds2, "flim");
dataGridView1.DataSource = ds.Tables["film"];
}
else
{
MessageBox.Show("没有找到结果");
}
}请问sda2这行到底哪里没关闭啊,我就是找不到原因...怎么解决
{
public Down()
{
InitializeComponent();
get();
} DataSet ds = new DataSet();
SqlDataAdapter da = null;
SqlConnection con = null; public void get()
{
try
{
con = GetCon.getCon();
con.Open();
string sql = "select film_name as '电影名',film_country as '国家',film_date as '日期',film_down as '下载地址' from dianying";
da = new SqlDataAdapter(sql, con);
da.Fill(ds, "Films");
DataGridViewLinkColumn lnk = new DataGridViewLinkColumn();
lnk.Text = "下载";
lnk.Name = "link";
lnk.HeaderText = "下载";
lnk.UseColumnTextForLinkValue = true;
dataGridView1.Columns.Add(lnk);
dataGridView1.DataSource = ds.Tables["Films"];
}
catch
{
MessageBox.Show("绑定失败");
}
finally
{ con.Close();
} } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridView dgv = (DataGridView)sender;
if (dgv.Columns[e.ColumnIndex].Name == "link")
{
string linkStr = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[4].Value.ToString(); try
{
Clipboard.SetText(linkStr);
MessageBox.Show("下载地址已经复制");
}
catch
{
MessageBox.Show("剪切板不能使用");
}
}
} private void button1_Click(object sender, EventArgs e)
{
con = GetCon.getCon();
string text = textBox1.Text.ToString() ;
string sql = "select film_name from dianying where film_name='" + text + "'";
string sql2 = "select film_name as '电影名',film_country as '国家',film_date as '日期',film_down as '下载地址' from dianying where film_name='"+textBox1.Text+"'";
using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
DataSet ds2 = new DataSet();
SqlDataAdapter sda2 = null;
if (sdr.Read())
{
sda2 = new SqlDataAdapter(sql2, con); //已有打开的与此命令相关联的 DataReader,必须首先将它关闭。
sda2.Fill(ds2, "flim");
dataGridView1.DataSource = ds.Tables["film"];
}
else
{
MessageBox.Show("没有找到结果");
}
}请问sda2这行到底哪里没关闭啊,我就是找不到原因...怎么解决
{
sdr.CLose();
sda2 = new SqlDataAdapter(sql2, con); //已有打开的与此命令相关联的 DataReader,必须首先将它关闭。
sda2.Fill(ds2, "flim");
dataGridView1.DataSource = ds.Tables["film"];
}