Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Dictionary<string, string>> RunSql(string sql)
- {
- List<Dictionary<string, string>> row = new List<Dictionary<string, string>>();
- SqlDataReader reader;
- SqlCommand cmd = this.getSqlCommand();
- cmd.CommandText = sql;
- if (transaction == false)
- {
- if (this.db.State == ConnectionState.Closed)
- {
- this.db.Open();
- }
- }
- reader = cmd.ExecuteReader();
- try
- {
- while (reader.Read())
- {
- Dictionary<string, string> coluna = new Dictionary<string, string>();
- for (int x = 0; x < reader.FieldCount; x++)
- {
- Type a = typeof(System.Byte[]);
- Object valor = reader[reader.GetName(x)];
- if (reader[reader.GetName(x)].GetType() == a)
- {
- System.Byte[] bytes = (System.Byte[])valor;
- coluna[reader.GetName(x)] = BitConverter.ToString(bytes);
- }
- else
- {
- coluna[reader.GetName(x)] = valor.ToString();
- }
- }
- row.Add(coluna);
- }
- if (transaction == false)
- {
- this.db.Close();
- }
- reader.Close();
- }
- catch (Exception e)
- {
- reader.Close();
- }
- return row;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement