我是 LINQ 的新手并通过 LINQ 填充 GridView。请看我的代码:
SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["mas"]);
DataSet ds = new DataSet();
string Query = string.Empty;
private void Bind_LINQ_To_DataSet()
{
Query = "select * from dbo.Movie";
SqlDataAdapter da = new SqlDataAdapter(Query, connection);
da.Fill(ds, "dbo.Movie");
var tbl = from p in ds.Tables["dbo.Movie"].AsEnumerable()
where p.Field<int>("ID") == Convert.ToInt32(TextBox1.Text)
select p;
GridView1.Visible = true;
GridView1.DataSource = tbl;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Bind_LINQ_To_DataSet();
}
我的 GridVIew 是空的。任何建议真的很感激。