[求助]这样写数据库连接对不对?
private void listBox1_Click(object sender, EventArgs e){
string strTableName = this.listBox1.SelectedValue.ToString();
using (SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=;database='" + strDatabase+"'"))
{
string strSql = "select * from '"+strTableName+"'";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(strSql,con);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt.DefaultView;
}
}
strTableName是从listbox控件获值
编译的时候说fill附近有错误。