例如我有这张表
EmployeeName EmpoyeeID
John Mark 60001
Bent Ting 60002
Don Park 60003
如何显示EmployeeID在数据表中有一个前导星号? 样品:* 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];
}
我需要在水晶报告中显示dataTable,并在员工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();
}
答案 0 :(得分:2)
Select '*'+id,col1,col2,col3 from employee
虽然最好的方法是在使用时修改列值。但显然,这比仅在查询中添加更令人头疼。
答案 1 :(得分:1)
将其添加到Crystal报表本身。
像 -
"*" & {tblTable.FieldName}
(虽然我不记得Crystal报告的语法,抱歉!)
答案 2 :(得分:1)
未经测试,但使用以下代码替换函数末尾的return语句应该有效:
DataTable table = ds.Tables[0];
DataTable clonedTable = table.Clone();
clonedTable.Columns["EmployeeID"].DataType = typeof(String);
foreach (DataRow row in table.Rows)
{
clonedTable.ImportRow(row);
}
foreach (DataRow row in clonedTable.Rows)
{
row["EmployeeID"] = "*" + row["EmployeeID"].ToString();
}
return clonedTable;
然而,正如其他人所说,我建议在读取数据时将asterick添加到某个地方而不是表格本身。