Fill DataSet with two tables
-
How to fill a dataset using two tables coz i want to use that dataset for crystal report.
-
How to fill a dataset using two tables coz i want to use that dataset for crystal report.
DataAdapter.Fill perhaps? If you're using SQL Server for your database, you can call a stored procedure that returns two result sets - each will be filled in the dataset as a separate DataTable. The stored procedure is simple:
CREATE PROCEDURE Sample
AS
BEGIN
select * from table1;
select * from table2;
END -
DataTable table1 = new DataTable(); DataTable table2 = new DataTable(); DataSet dataSet = new DataSet(); dataSet.Tables.Add(table1); dataSet.Tables.Add(table2);
the code is like this.. SqlCommand cmd; SqlConnection conn; SqlDataAdapter sda; conn = new SqlConnection("server=Sai2; database=Inventory; uid=sa; pwd=123456;"); cmd = conn.CreateCommand(); cmd.CommandText = "select * from stock"; sda = new SqlDataAdapter(); sda.SelectCommand = cmd; DataS.Stock ds = new SisInventorySystem.DataS.Stock(); sda.Fill(ds, "stock"); Crystal_Reports.TotalStockRpt TtlStkRpt = new SisInventorySystem.Crystal_Reports.TotalStockRpt(); TtlStkRpt.SetDataSource(ds); crystalReportViewer1.ReportSource = TtlStkRpt; crystalReportViewer1.DisplayToolbar = true; Now i have to run one more Query "select * from Company" having nothing in common between table company and stock.
-
How to fill a dataset using two tables coz i want to use that dataset for crystal report.
With SQL Server: "SELECT * FROM Table1 ; SELECT * FROM Table2" (Other database engines don't allow multiple statements in a command.)
-
the code is like this.. SqlCommand cmd; SqlConnection conn; SqlDataAdapter sda; conn = new SqlConnection("server=Sai2; database=Inventory; uid=sa; pwd=123456;"); cmd = conn.CreateCommand(); cmd.CommandText = "select * from stock"; sda = new SqlDataAdapter(); sda.SelectCommand = cmd; DataS.Stock ds = new SisInventorySystem.DataS.Stock(); sda.Fill(ds, "stock"); Crystal_Reports.TotalStockRpt TtlStkRpt = new SisInventorySystem.Crystal_Reports.TotalStockRpt(); TtlStkRpt.SetDataSource(ds); crystalReportViewer1.ReportSource = TtlStkRpt; crystalReportViewer1.DisplayToolbar = true; Now i have to run one more Query "select * from Company" having nothing in common between table company and stock.
-
DataAdapter.Fill perhaps? If you're using SQL Server for your database, you can call a stored procedure that returns two result sets - each will be filled in the dataset as a separate DataTable. The stored procedure is simple:
CREATE PROCEDURE Sample
AS
BEGIN
select * from table1;
select * from table2;
END -
ok... and after what to write... da.fill(ds,"whichtable"); can i write the both table....
Access the tables through the DataSet's
Tables
collection:DataTable dt0 = ds.Tables[0]; // first result set from the batch queries
DataTable dt1 = ds.Tables[1]; // second result set from the batch queries -
Access the tables through the DataSet's
Tables
collection:DataTable dt0 = ds.Tables[0]; // first result set from the batch queries
DataTable dt1 = ds.Tables[1]; // second result set from the batch queries -
Done All the things but can not Solved ... sda.fill(ds,"Table name Is Must.") Is there any Solution...
Why is the table name a must upon filling? You can always change the table name (if you really need to) after filling the set like this:
sda.Fill(ds);
ds.Tables[0].TableName = "tableNameIsAMust.";
ds.Tables[1].TableName = "somethingElse";Or is it that you are looking to execute two queries separately (instead of together in one batch)? In that case, you could supply separate table names upon filling:
da1.Fill(ds, "Table1");
da2.Fill(ds, "Table2");I'm having difficulty understanding exactly why this is problematic for you. Can you explain?
-
Why is the table name a must upon filling? You can always change the table name (if you really need to) after filling the set like this:
sda.Fill(ds);
ds.Tables[0].TableName = "tableNameIsAMust.";
ds.Tables[1].TableName = "somethingElse";Or is it that you are looking to execute two queries separately (instead of together in one batch)? In that case, you could supply separate table names upon filling:
da1.Fill(ds, "Table1");
da2.Fill(ds, "Table2");I'm having difficulty understanding exactly why this is problematic for you. Can you explain?