|
|
|
สอบถาม CrystalReportViewer การนำค่า SQL ไปเก็บใน DataSet ค่ะ |
|
|
|
|
|
|
|
อยากทราบว่า เราจะนำ sql มากเก็บใน Datasetยังไงอ่ะคะ จะเอาไปทำCrystalReportViewer อ่ะคะ
Code (C#)
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string Departname = DropDownList2.SelectedValue;
string DepartID = DropDownList1.SelectedValue;
string sqlcon = "Data Source=.;Initial Catalog=MOOAE-PC;User Id=cpcrop;Password=cps";
string sql = "";
if (DepartID == "3" & Departname == "กรุณาเลือก")
{
sql = "SELECT Person.Prefix, Person.Name, Person.Lastname, Land.Num_land, Land.Block, Land.IDland, Land.Area_rai, Land.Area_ngan, Land.Area_square, Land.Area_rai_ns, Land.Area_ngan_ns, Land.Area_square_ns FROM Department INNER JOIN Person ON Department.ID_Department = Person.ID_Department CROSS JOIN Land WHERE (Department.Parent_ID = '3') ";
}
if (DepartID == "7" & Departname == "กรุณาเลือก")
{
sql = "SELECT Person.Prefix, Person.Name, Person.Lastname, Land.Num_land, Land.Block, Land.IDland, Land.Area_rai, Land.Area_ngan, Land.Area_square, Land.Area_rai_ns, Land.Area_ngan_ns, Land.Area_square_ns FROM Department INNER JOIN Person ON Department.ID_Department = Person.ID_Department CROSS JOIN Land WHERE (Department.Parent_ID = '7')";
}
if (DepartID == "3" & Departname == "1")
{
sql = "SELECT Person.Prefix, Person.Name, Person.Lastname, Land.Num_land, Land.Block, Land.IDland, Land.Area_rai, Land.Area_ngan, Land.Area_square, Land.Area_rai_ns, Land.Area_ngan_ns, Land.Area_square_ns, Department.Departmentname FROM Department INNER JOIN Person ON Department.ID_Department = Person.ID_Department INNER JOIN Land ON Person.num_land = Land.Num_land WHERE (Department.Departmentname = '1') AND (Department.Parent_ID = '3')";
}
if (DepartID == "7" & Departname == "1")
{
sql = "SELECT Person.Prefix, Person.Name, Person.Lastname, Land.Num_land, Land.Block, Land.IDland, Land.Area_rai, Land.Area_ngan, Land.Area_square, Land.Area_rai_ns, Land.Area_ngan_ns, Land.Area_square_ns, Department.Departmentname FROM Department INNER JOIN Person ON Department.ID_Department = Person.ID_Department INNER JOIN Land ON Person.num_land = Land.Num_land WHERE (Department.Departmentname LIKE '1') AND (Department.Parent_ID = '7')";
}
if (DepartID == "3" & Departname == "2")
{
sql = "SELECT Person.Prefix, Person.Name, Person.Lastname, Land.Num_land, Land.Block, Land.IDland, Land.Area_rai, Land.Area_ngan, Land.Area_square, Land.Area_rai_ns, Land.Area_ngan_ns, Land.Area_square_ns, Department.Departmentname FROM Department INNER JOIN Person ON Department.ID_Department = Person.ID_Department INNER JOIN Land ON Person.num_land = Land.Num_land WHERE (Department.Departmentname LIKE '2') AND (Department.Parent_ID = '3')";
}
if (DepartID == "7" & Departname == "2")
{
sql = "SELECT Person.Prefix, Person.Name, Person.Lastname, Land.Num_land, Land.Block, Land.IDland, Land.Area_rai, Land.Area_ngan, Land.Area_square, Land.Area_rai_ns, Land.Area_ngan_ns, Land.Area_square_ns, Department.Departmentname FROM Department INNER JOIN Person ON Department.ID_Department = Person.ID_Department INNER JOIN Land ON Person.num_land = Land.Num_land WHERE (Department.Departmentname LIKE '2') AND (Department.Parent_ID = '7')";
}
string strConn = WebConfigurationManager.ConnectionStrings["LandConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(strConn);
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("..\\Report\\ParentCrystalReport.rpt"));
rpt.SetDatabaseLogon("", "");
rpt.SetDataSource(ds);
rpt.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
rpt.PrintOptions.PaperSize = PaperSize.PaperLegal;
rpt.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrystalReportViewer1.ReportSource = rpt;
}
}
Tag : ASP.NET, Crystal Report
|
|
|
|
|
|
Date :
2011-08-15 15:23:33 |
By :
mooaee |
View :
987 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันก็ได้เป็น DataSet ถูกแล้วน่ะครับ
Code (C#)
rpt.SetDataSource(ds);
|
|
|
|
|
Date :
2011-08-15 20:55:41 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|