Binding Local Dataset To Reportviewer In ASP.net C# - asp.net

I want to bind dataset's data to ReportViewer object , I create rdlc report and set it as ReportViewer's report source in design view , but it doesn't show anything ,I checked dataset's data by binding gridview and it's work and show the data in gridview but in ReportViewer object doesn't , Please Help . Here is the code:1(Note: "Temp" is the table's Name of database , that's i want to bind to ReportViewer)2(I don't want to use xsd dataset item)
string path = #"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True";
SqlConnection con1 = new SqlConnection(path);
con1.Open();
const string query = "select * From [Table1] where date between #from and #to";
SqlCommand com1 = new SqlCommand(query, con1);
com1.Parameters.AddWithValue("#from", DateTime.Parse(r1));
com1.Parameters.AddWithValue("#to", DateTime.Parse(r2));
SqlDataAdapter adp1 = new SqlDataAdapter(com1);
DataSet ds1 = new DataSet();
adp1.Fill(ds1);
com1.ExecuteNonQuery();
con1.Close();
GridView1.DataSource = ds1;
GridView1.DataBind();
ReportViewer1.Reset();
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Temp", ds1.Tables[0]));
ReportViewer1.LocalReport.Refresh();

If you have not done so, you also need to add controls like textboxes or tables to the report and create expressions that reference the fields in the dataset. For example, you could click on the Toolbox in visual studio, and drag a textbox to the report designer. Then right click the textbox, and choose Expression. When the Expression dialog box appears, look in the Category section for Fields(nameofYourDataset), click it, and look in the Values section for the names of fields from your dataset. Double click one of them which will populate the top section, and click OK.

Related

Display arabic names in ASP.Net from database

I have the following query in ASP.Net page:
SELECT 'محاولة'
This query is printing a hard coded Arabic word. I am saving this record in a DataTable and then printing on page in GridView (by passing that DataTable to GridView) but this Arabic word is being printed as square boxes.
How to print this word properly on ASP.Net page? I tried using following but it didn't work.
SELECT N'محاولة'
EDIT
Here's my code.
DataTable dt = new DataTable();
string sql = "SELECT 'محاولة'";
command.Connection = con;
command.CommandType = CommandType.Text;
command.CommandText = sql;
reader = command.ExecuteReader();
dt.Load(reader);
And then I am passing this "dt" to gridview control.
GridView1.DataSource = dt;
GridView1.DataBind();
Grid view is printing that Arabic word as square boxes (screenshot below).
Let assume your table structure is as fallow.
Create table Arabic(
id int primary key identity,
Title narchar(100),
);
Now lets add some demo data.
Insert into Arabic values (N'محاوله');
After adding data correctly there you won't have any problem with loading it asp.net page.

auto update table in asp.net

I have a problem. I was trying to make a table on a website. Everytime the user add a record it would display on the website. The user can add many more record on the table. My question is how do i make the table display the record automatically without saving the data into a database and retreiving it to dispaly on the the website table?
You can take benefit of gridview, datatable and viewstate.
Initially you can create a datatable and bind it in gridview
Also keep the datatable in the viewstate
Next time when user add some data add a new row in data-table
Update the viewstate data.
And again Bind the gridview.
Edit 1
Adding data to datatable
DataTable dt=new DataTable();
dt.column.Add("Name",typeof(string));
dt.column.Add("Age",typeof(int));
DataRow dr=dt.NewRow();
dr["Name"]="Mohammad"; // or dr[0]="Mohammad";
dr["Age"]=24; // or dr[1]=24;
dt.add.rows(dr);
dr=dt.NewRow();
dr["Name"]="Shahnawaz"; // or dr[0]="Shahnawaz";
dr["Age"]=24; // or dr[1]=24;
dt.add.rows(dr);
GridView1.DataSource=dt;
GridView1.DataBind();
store your datatable in view state
ViewState["dataTable"] = dt;
Now suppose you have text boxes t1 and t2
Datatable dt=ViewState["dataTable"] as DataTable;
dr=dt.NewRow();
dr["Name"]=t1.text; // or dr[0]="Shahnawaz";
dr["Age"]=t2.text; // or dr[1]=24;
dt.add.rows(dr);
Bind it to gridview again
GridView1.DataSource=dt;
GridView1.DataBind();
and keep the datatable in the view state
ViewState["dataTable"] = dt;

Bind RadComboBox to ObjectDataSource using DataSet

I'm trying to bind a RadComboBox to an ObjectDataSource whose select method returns a DataSet object. I get an error: "'FieldName', is neither a DataColumn nor a DataRelation for table Table". Just to be sure I'm not crazy, I tried the same with a DropDownList which worked perfectly. I found in Telerik's docs that they support using an ObjectDataSource that returns IEnumerable objects. So, am I correct that the RadControls don't support using ObjectDataSource when it is using a DataSet? Really?
The link you provided points to a different control. See here for the combobox, which is the control in your question title.
The combobox control easily accepts datatable objects from datasets as a source of what to display in the combobox.
Then the combobox control:
Select the GetData method (the only option) and then configure your combobox:
Run:
EDIT:
There seems to be no reason to use a ObjectDataSource if you are already using a dataset and SqlDataAdapter :
DataSet myDataset = new DataSet();
SqlConnection con = new SqlConnection(#"Data Source=J-PC\SQLEXPRESS;Initial Catalog=SO;Integrated Security=True");
SqlDataAdapter adapter = new SqlDataAdapter(#"SELECT TOP (25) Leg_FirstName FROM GRS_Legislator ORDER BY Leg_FirstName", con);
adapter.Fill(myDataset);
RadComboBox1.DataTextField = "Leg_FirstName";
RadComboBox1.DataValueField = "Leg_FirstName";
RadComboBox1.DataSource = myDataset;
RadComboBox1.DataBind();

ASP.NET Datalist Sorting (XMl Source)

I am populating a datalist control with a simple xml source. It displays some Dates in whatever order they are displayed in the xml file. I want them to be sorted before they are displayed in the Datalist. Can this be done?
Depends on how you load the xml, if you load the XML into a dataset you can sort before binding.
DataSet myDataSet = new DataSet();
myDataSet.ReadXML("mydata.xml");
DataView myDataView = new DataView(myDataSet.Tables[0]);
myDataView.Sort = "mySortField ASC"; //or DESC
myDataListControl.DataSource = myDataView;
myDataListControl.DataBind();

Using untyped datasets in Crystal Reports

I'm creating a runtime dataset in page load. In this dataset I'm adding columns like that:
CrystalDecisions.CrystalReports.Engine.ReportDocument orpt =
new CrystalDecisions.CrystalReports.Engine.ReportDocument();
DataTable table = new DataTable("DataSet1");
table.Columns.Add("Fname", typeof(System.String));
table.Columns.Add("Lname", typeof(System.String));
table.Columns.Add("Salary", typeof(System.String));
DataRow row = table.NewRow();
row["Fname"] = "Mathew";
row["Lname"] = "Hayden";
row["Salary"] = "5000$";
table.Rows.Add(row);
ds.Tables.Add(table);
orpt.Load(MapPath("CrystalReport3.rpt"));
orpt.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = orpt;
Records are not displayed in CrystalReport3.rpt when I'm going to run the program.
Please tell me how to set these coloums in Crystal Reports 3!
What happens if you move your code from the Page_Load to the Page_Init event handler of the ASP.NET page?
Try to set the AutoDataBind property to "true":
Gets or sets whether automatic data
binding to a report source is used. If
the value is set to True, the
DataBind() method is called after
OnInit() or Page_Init() events.
Another tip: did you try to call the RefreshReport() (or Refresh() in older versions) method of your CrystalReportViewer1 object?
Instead of
orpt.SetDataSource(ds.Tables[0]);
Do
orpt.SetDataSource(ds.Tables["table_name"]);
table_name is the table name you gave for the table

Resources