我的第一个存储过程如下所示:
Use [Stock]
Go
Create Proc Get_Orders
AS
SELECT [Number_Order]
,[Date_Order]
,[FullName]
,[Location]
FROM [Order]
我的第二个存储过程如下所示:
USE [Stock]
GO
ALTER Proc [dbo].[Get_Order_Res]
AS
SELECT i.Name_Item
,od.[ID_Order]
,od.[Project]
,od.[Length]
,od.[Width]
,od.[Quantity]
,od.[Weight]
,od.[Supplier]
,od.[GDS_Name]
,od.[GDS_Date]
,od.[WorkshopName]
,od.[WorkshopDate]
,od.[ReservedQty]
FROM OdredDetails od
INNER JOIN ItemQuantity iq
ON iq.ID_ItemQte = od.ID_ItemQte
INNER JOIN item i
ON i.ID_Item = iq.ID_Item
INNER JOIN [Order] ord
ON ord.Number_Order=od.ID_Order
where ord.[Location]='PRODUCTION'
在我的c#代码中,我使用此代码从存储过程中获取数据
public DataTable Get_Order_Res()
{
DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
DataTable dt = new DataTable();
dt = DAL.SelectData("Get_Order_Res", null);
DAL.Close();
return dt;
}
public DataTable Get_Orders()
{
DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
DataTable dt = new DataTable();
dt = DAL.SelectData("Get_Orders", null);
DAL.Close();
return dt;
}
并以我的形式使用此代码创建主详细信息视图
public partial class FRM_Reserved : Form
{
BL.CLS_Order ord = new BL.CLS_Order();
DataTable master = new DataTable();
DataTable details = new DataTable();
DataSet dataSet = new DataSet();
public FRM_Reserved()
{
InitializeComponent();
master = ord.Get_Orders();
details = ord.Get_Order_Res();
dataSet.Tables.Add(master);
dataSet.Tables.Add(details);
dataSet.Relations.Add("OderDetails",
dataSet.Tables["master"].Columns["Number_Order"],
dataSet.Tables["details"].Columns["ID_Order"]);
gridControl3.DataSource = dataSet.Tables["master"];
答案 0 :(得分:1)
由于您没有为数据表指定名称,因此当您尝试访问它们时,它将返回null。
dataSet.Tables["master"] // this returns null
要解决此问题,请为数据表命名
DataTable master = new DataTable("master");
DataTable details = new DataTable("details");