2

例如我有这张桌子

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];
    }

我需要在水晶报表中显示数据表,并在员工 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();
    }
4

3 回答 3

2

简单但不是最好的方法是以该格式获取数据,当且仅当它不打算在其他任何地方使用时。您可以在查询中执行此操作

Select '*'+id,col1,col2,col3 from employee

虽然最好的方法是在使用时修改列值。但显然这比简单地在查询中添加更令人头疼。

于 2013-08-07T15:07:15.093 回答
1

将其添加到 Crystal 报表本身。

就像是 -

"*" & {tblTable.FieldName}

(虽然我不记得水晶报表的语法了,抱歉!)

于 2013-08-07T15:05:55.193 回答
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;

但是,正如其他人所说,我建议在读取数据时在某处添加星号,而不是在表本身中添加星号。

于 2013-08-07T15:06:13.883 回答