Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. public DataTable GetTable2()
  2.     {
  3.         // Here we create a DataTable with four columns.
  4.         DataTable table = new DataTable();
  5.         table.Columns.Add("Dosage", typeof(int));
  6.         table.Columns.Add("Drug", typeof(string));
  7.         table.Columns.Add("Patient", typeof(string));
  8.         table.Columns.Add("Date", typeof(DateTime));
  9.         table.Columns.Add("testColumn", typeof(DateTime));
  10.  
  11.  
  12.         SqlConnection connection = new SqlConnection();
  13.         connection = Connection.getConnection();
  14.         connection.Open();
  15.  
  16.  
  17.         string tableName = "";
  18.  
  19.         tableName += "Subject";
  20.  
  21.  
  22.         string Query = "select * from " + tableName + " where Status = 0;";
  23.  
  24.  
  25.         SqlDataAdapter da = new SqlDataAdapter(Query, connection);
  26.         DataSet ds = new DataSet();
  27.         da.Fill(ds);
  28.         DataRowCollection collection = ds.Tables[0].Rows;
  29.         foreach (DataRow row in collection)
  30.         {
  31.  
  32.             // Here we add five DataRows.
  33.             table.Rows.Add(25, "Indocin", "David", DateTime.Now);
  34.             table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
  35.             table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
  36.             table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
  37.             table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
  38.  
  39.         }
  40.  
  41.  
  42.         connection.Close();
  43.  
  44.         return table;
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement