PDA

View Full Version : آموزش: استفاده کند DataTable در فرم اسمولیت



fakhravari
چهارشنبه 27 اردیبهشت 1391, 00:09 صبح
با سلام
من 2 تا تیبل ساختم به نام t1,t2 , با دیتاسورس Database1
حالا چطوری باید در فرم این 2 را فراخونی کنم.
List1 وList2 به صورت داده میان توی جدول
با این کد نمیشه

DataSet Ds = new DataSet();

Ds.Tables.Add(List1());
Ds.Tables.Add(List2());

StiReport r = new StiReport();
r.Load(Server.MapPath(@"Report.mrt"));

r.RegData("Database1", Ds);
StiWebViewer1.Report = r;
StiWebViewer1.DataBind();

fakhravari
شنبه 25 شهریور 1391, 01:09 صبح
به این روش .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Stimulsoft.Report;
using System.Data.SqlClient;
using System.Data;
using Stimulsoft.Report.Dictionary;
using Stimulsoft.Report.Web;
using Stimulsoft.Report.Export;
using System.IO;

namespace WebApplication18
{
public partial class WebForm1 : System.Web.UI.Page
{

public DataTable CatGory_List1()
{
SqlConnection con = new SqlConnection(@"Data Source=COMPUTER1\SQLEXPRESS;Initial Catalog=ss;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT id, CatName FROM CatGory";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
return dt;
}
public DataTable Furom_List2()
{
SqlConnection con = new SqlConnection(@"Data Source=COMPUTER1\SQLEXPRESS;Initial Catalog=ss;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT id, listname, CatGoryid, date FROM Furom";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
return dt;
}
public DataTable posting_List3()
{
SqlConnection con = new SqlConnection(@"Data Source=COMPUTER1\SQLEXPRESS;Initial Catalog=ss;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT Furomid, id, text1, text2 FROM posting";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
return dt;
}







protected void Page_Load(object sender, EventArgs e)
{



using (StiReport report = new StiReport())
{
report.Load(HttpContext.Current.Server.MapPath(@"StiWebReport1.mrt"));

report.Render(false);

StiOptions.Web.AllowUseResponseFlush = false;
Stimulsoft.Report.Export.StiWord2007ExportSettings x = new Stimulsoft.Report.Export.StiWord2007ExportSettings ();

StiReportResponse.ResponseAsWord2007(this.Page, report, x);
}





DataTable dt1 = new DataTable("cat");
DataTable dt2 = new DataTable("froum");
DataTable dt3 = new DataTable("posting");
dt1 = CatGory_List1();
dt2 = Furom_List2();
dt3 = posting_List3();
StiReport r = new StiReport();

r.Load(Server.MapPath(@"Report.mrt"));

r.RegData("cat", dt1);
r.RegData("posting", dt3);
r.RegData("froum", dt2);

StiWebViewer1.Report = r;
StiWebViewer1.DataBind();
}

protected void Button1_Click(object sender, EventArgs e)
{

}



}
}

kimia**
جمعه 07 مهر 1391, 18:40 عصر
سلام
من میخوام یک db رو به فرم های وب سایتم که با visual stadio ساختم وصل کنم ولی نمی دونم چطوری باید این کارو انجام بدم