DataTable And DataRow
- public DataTable TranslateDataTable(DataTable table)
- {
- DataTable dt = new DataTable();
- dt.TableName = "TempTable";
-
- if (table != null && table.Rows.Count > 0)
- {
-
- foreach (DataColumn column in table.Columns)
- {
- string name = GetColumnName(column.ColumnName);
- dt.Columns.Add(name);
- }
-
- for (int i = 0; i < table.Rows.Count; i++)
- {
- DataRow NewRow = dt.NewRow();
- DataRow row = table.Rows[i];
-
- for (int j = 0; j < dt.Columns.Count; j++)
- {
- NewRow[j] = row[j].ToString();
- }
-
- dt.Rows.Add(NewRow);
- }
- }
- return dt;
- }
-
- private string GetColumnName(string columnName)
- {
- string sqlString = " Select TRANSLATION from COLUMNTRANSLATION where COLUMNNAME = '" + columnName.ToUpper() + "'";
-
- object s = dao.ExecuteScalar(sqlString);
- string name = (s == null) ? columnName : s.ToString();
- return name;
- }