Advertisement
Guest User

Класс запросов sql

a guest
Jan 17th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using ExcelOpenSQL;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace ExscelOpenSQL
  10. {
  11.     class SQLOpen
  12.     {
  13.         /// <summary>
  14.         /// удаление базы
  15.         /// </summary>
  16.         /// <param name="connectionString"></param>
  17.         public void deleteOutputPrice(string connectionString)
  18.         {
  19.             using (SqlConnection con = new SqlConnection(connectionString))
  20.             {
  21.                 con.Open();
  22.                 using (SqlCommand com = new SqlCommand("DELETE FROM OutputPrice", con))
  23.                 {
  24.                     com.ExecuteNonQuery();
  25.                 }
  26.             }
  27.         }
  28.  
  29.         /// <summary>
  30.         /// добавление в базу
  31.         /// </summary>
  32.         /// <param name="list"></param>
  33.         /// <param name="connectionString"></param>
  34.         public void addDB(string [,] list, string connectionString)
  35.         {
  36.             using (SqlConnection con = new SqlConnection(connectionString))
  37.             {
  38.                 ExcelFile ex = new ExcelFile();
  39.                 con.Open();
  40.                 for (int i = 0; i < list.GetLength(1); i++)
  41.                 {
  42.                     using (SqlCommand com = new SqlCommand("INSERT INTO Price(name, priceUSD, priceBYR) VALUES(@name, @priceUSD, @priceBYR)", con))
  43.                     {
  44.                         com.Parameters.AddWithValue("@name", list[1, i]);
  45.                         com.Parameters.AddWithValue("@priceUSD", list[2, i]);
  46.                         com.Parameters.AddWithValue("@priceBYR", list[3, i]);
  47.                         com.ExecuteNonQuery();
  48.                         com.Dispose();
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement