【发布时间】:2019-12-01 07:38:10
【问题描述】:
按下按钮后,我尝试使用来自 SQL 服务器的数据库和其他表来更新我的 ASP.net 站点上的 GridView,但它没有改变,没有“捕获”。
GridView 没有出现。
{
SqlConnection sqlConnection1;
sqlConnection1 = new SqlConnection(@"Data Source=ELAD_HA\SQLEXPRESS;Initial Catalog=Users;Integrated Security=True");
SqlCommand sqlCommand1;
sqlCommand1 = new SqlCommand("SELECT * FROM TBUsers ORDER BY Name", sqlConnection1);
try
{
DataSet ds = new DataSet();
SqlDataAdapter adptr = new SqlDataAdapter(sqlCommand1);
SqlCommandBuilder comb = new SqlCommandBuilder(adptr);
adptr.Fill(ds,"T1");
GridView2.DataSource = ds.Tables["T1"];
//GridView2.DataSource = ds;
//GridView2.DataMember = "T1";
}
catch (SqlException ex)
{
SuccessLabel1.Text = ex.Message.ToString();
}
}
代码有什么问题?
附言
我可以将 DataSource 更改为从菜单中选择 Data Source 的 GridView 吗? (从“拆分”屏幕)。
感谢帮助。
【问题讨论】:
标签: c# asp.net database dataset sqlcommand