Guest User

Untitled

a guest
Jun 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. using (var context = new RcoreContext())
  2. {
  3. // creates a Command
  4. var command = context.Database.Connection.CreateCommand();
  5. command.CommandType = commandType;
  6. command.CommandText = sql;
  7.  
  8. using (SqlDataReader reader = command.ExecuteReader())
  9. {
  10. while (reader.Read())
  11. {
  12. for (int i = 0; i < reader.FieldCount; i++)
  13. {
  14. Console.WriteLine(reader.GetValue(i));
  15. }
  16. Console.WriteLine();
  17. }
  18. }
  19. }
  20.  
  21. _dbContext.Database.ExecuteSqlCommand(sql, parameters);
  22. _dbContext.Database.SqlQuery<TEntity>(sql, parameters);
  23.  
  24. using (var connection = context.Database.GetDbConnection())
  25. using (var command = context.Database.GetDbConnection().CreateCommand())
  26. {
  27. command.CommandText = string.Format(sqlQuery, id);
  28. connection.Open();
  29. using (var reader = command.ExecuteReader()){}
  30. }
  31.  
  32. using (var connection = new SqlConnection(_dbContext.Database.Connection.ConnectionString))
  33. using (var cmd = new SqlCommand())
  34. {
  35. cmd.Connection = connection;
  36. cmd.CommandText = "your query here";
  37. cmd.CommandType = CommandType.Text;
  38.  
  39. cmd.Parameters.Add("@param1", SqlDbType.Int);
  40.  
  41. cmd.Connection.Open();
  42. cmd.ExecuteNonQuery();
  43. }
Add Comment
Please, Sign In to add comment