Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. public static DataTable SelectRecordsFromTable(Table tableName)
  2.         {
  3.             string connectionStringToDatabase = BuildConnectionString();
  4.             SqlConnection sqlConnection = new SqlConnection(connectionStringToDatabase);
  5.             sqlConnection.Open();
  6.             string sqlExpression = String.Format("SELECT * FROM {0}", Convert.ToString(tableName));
  7.             SqlCommand sqlCommand = new SqlCommand();
  8.             sqlCommand.Connection = sqlConnection;
  9.             sqlCommand.CommandText = sqlExpression;
  10.             SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
  11.             DataSet dataSet = new DataSet();
  12.             sqlDataAdapter.Fill(dataSet);
  13.             DataTable records = dataSet.Tables[0];
  14.             sqlConnection.Close();
  15.             return records;
  16.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement