// Connection string
String connstr = "Data Source =.; initial catalog = wwalmdb; user id = sa; Password = sqlsql ";
// Create a connection
Sqlconnection connection = new sqlconnection (connstr );
// Query command
Sqlcommand command = new sqlcommand (textboxsql. Text, connection );
// Adapter
Sqldataadapter adapter = new sqldataadapter (command );
// Dataset
Dataset DS = new dataset ();
// Query and fill
Try
{
Connection. open ();
Adapter. Fill (DS );
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
}
Finally
{
Connection. Close ();
Command. Dispose ();
Connection. Dispose ();
}
// Specify the rdlc report
This. reportviewer1.localreport. reportembeddedresource = "formreport. eventreport. rdlc ";
// Clear the previous reportviewer Data Source
This. reportviewer1.localreport. CES. Clear ();
// Create a data source
Reportdatasource rs = new reportdatasource ();
Rs. Name = "eventhistory"; // "eventhistory" is the name of the dataset under the tablib attribute of the rdlc report.
Rs. value = Ds. Tables [0];
// Add a data source
This. reportviewer1.localreport. CES. Add (RS );
// Display data
This. reportviewer1.refreshreport ();