一个简单的C#代码
小弟刚学C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(@"Data Source =.\SQLEXPRESS;AttachDBFilename=C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\DB_DataBase.mdf;Integrated Security=True;
User Instance=true;"))
{
// string sql = "SELECT name FROM SysColumns WHERE SysColumns.id=object_id('" + comboBox1.Text + "')";
//string sql="SELECT * FROM "+comboBox1.Text;
string table=comboBox1.Text;
string sql = string.Format("SELECT * FROM {0}",table);
con.Open();
SqlDataAdapter ada = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
ada.Fill(ds,"table");
dataGridView1.DataSource = ds.Tables[0];
con.Close();
}
}
提示说:对象名 'System.Data.DataRowView' 无效。
怎么改代码……