[英]Use data from returning datatable?
我有一個這樣的數據表功能
public DataTable LoadCategory(SetupCategoryBO scBO)
{
DBConnect myConnection = new DBConnect();
myConnection.connection.Open();
SqlCommand comm = new SqlCommand("ph.setup_category_proc", myConnection.connection);
comm.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
try
{
comm.Parameters.AddWithValue("@unitID", scBO.UnitID);
comm.Parameters.AddWithValue("@objectID", scBO.ObjectID);
comm.Parameters.AddWithValue("@user", scBO.UserID);
comm.Parameters.AddWithValue("@flag", scBO.Flag);
comm.Parameters.AddWithValue("@parentID", scBO.ParID);
comm.UpdatedRowSource = UpdateRowSource.None;
da.SelectCommand = comm;
da.Fill(ds, "CategoryTable");
return ds.Tables["CategoryTable"];
}
我用它來嘗試從數據表中獲取數據
DataTable dt = new DataTable();
dt = Scdal.LoadCategory(ScBo);
datagrid.Datacontext=dt;
我應該使用Sql數據適配器嗎?DataGrid顯示空白
和SetupCategoryBO只是用來初始化值。據我所知,值很好。
我在這里做錯了什么?
試試這個代碼。
DataTable dt = Scdal.LoadCategory(ScBo);
datagrid.Datacontext=dt.DefaultView;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.