HyugaPaolo

C# procedure (SEE PROCEDURE Sql server)

Oct 2nd, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data;
  7. using System.Data.Sql;
  8. using System.Data.SqlClient;
  9.  
  10. namespace sqlTest
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             string connString = @"Data Source=.\;Initial ...";
  17.             SqlConnection cnn = new SqlConnection(connString);
  18.             cnn.Open();
  19.             SqlCommand cmd = cnn.CreateCommand();
  20.  
  21.             cmd.CommandText = "sp_Category_Ins";
  22.             cmd.CommandType = CommandType.StoredProcedure;
  23.             cmd.Parameters.AddWithValue("@nomeCat","Spazzacamino");
  24.             int nr = cmd.ExecuteNonQuery();
  25.  
  26.             //if the query returns a table
  27.             SqlCommand cmdR = new SqlCommand("sp_POIforCategory");
  28.             cmdR.CommandType = CommandType.StoredProcedure;
  29.             cmdR.Parameters.AddWithValue("@nomeCat", "Spazzacamino");
  30.  
  31.  
  32.             //Version 1
  33.             SqlDataReader drR = cmdR.ExecuteReader();
  34.             DataTable tb1 = new DataTable();
  35.             tb1.Load(drR);
  36.  
  37.             //Version 2
  38.             SqlDataAdapter daR = new SqlDataAdapter(cmdR);
  39.             daR.Fill(tb1);
  40.  
  41.             foreach (DataRow dr in tb1.Rows) {/*...................*/ }
  42.  
  43.             cnn.Close();
  44.  
  45.  
  46.  
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment