例如,我有這個表修改數據表
EmployeeName EmpoyeeID
John Mark 60001
Bent Ting 60002
Don Park 60003
我如何可以顯示僱員有在數據表中的前導星號? 示例:* 60001 * 60002 * 60003
public DataTable ListOfEmployee()
{
DataSet ds = null;
SqlDataAdapter adapter;
try
{
using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand mySqlCommand = new SqlCommand("Select * Employee", myDatabaseConnection))
{
ds = new DataSet();
adapter = new SqlDataAdapter(mySqlCommand);
adapter.Fill(ds, "Users");
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return ds.Tables[0];
}
我需要顯示在水晶報表數據表與員工ID前導星號
public void Employees()
{
ReportDocument rptDoc = new ReportDocument();
Employees ds = new Employees(); // .xsd file name
DataTable dt = new DataTable();
// Just set the name of data table
dt.TableName = "Employees";
dt = ListOfEmployee(); //This function is located below this function
ds.Tables[0].Merge(dt);
string strReportName = "Employees.rpt";
string strPath = Application.StartupPath + "\\Reports\\" + strReportName;
// Your .rpt file path will be below
rptDoc.Load(strPath);
//set dataset to the report viewer.
rptDoc.SetDataSource(ds);
ReportViewer newReportViewer = new ReportViewer();
newReportViewer.setReport(rptDoc);
newReportViewer.Show();
}
有很多方法可以做到這一點,每個方法都是「最好的」方式,具體取決於在查詢出數據後你將如何處理數據。你能解釋更多(通過編輯原始問題)你查詢數據後對數據做什麼? –
顯示它在哪裏?這個問題不是很清楚,爲什麼你不加星號?例如。 string astData =「*」+ table.GetField(「EmpoyeeID」)。ToString(); –
最好的解決方案是在消耗數據的地方附加星號,而不是在數據表中。 – Khan