2013-08-07 56 views
2

例如,我有这个表修改数据表

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(); 
    } 
+0

有很多方法可以做到这一点,每个方法都是“最好的”方式,具体取决于在查询出数据后你将如何处理数据。你能解释更多(通过编辑原始问题)你查询数据后对数据做什么? –

+0

显示它在哪里?这个问题不是很清楚,为什么你不加星号?例如。 string astData =“*”+ table.GetField (“EmpoyeeID”)。ToString(); –

+0

最好的解决方案是在消耗数据的地方附加星号,而不是在数据表中。 – Khan

回答

2

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

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

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

1

将其添加到Crystal报表本身。

喜欢的东西 -

"*" & {tblTable.FieldName} 

1

没有测试,但在你的函数与最终替换return语句(虽然我不记得语法Crystal报表,对不起!)下面的代码应该工作:

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向下行,当数据被读取,而不是到TABL e本身。