Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CREATE PROC uspGetCity (@id nvarchar(5))
- //AS
- //SELECT City from Customers WHERE CustomerID = @id
- //GO
- using System;
- using System.Data.SqlClient;
- namespace DBTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- SqlConnection cnn;
- string connectionString = "Server=.;Database=Northwind;Integrated Security=true";
- cnn = new SqlConnection(connectionString);
- try
- {
- cnn.Open();
- Console.WriteLine("Connection Open ! ");
- //string sql = "Select * from customers";
- //string inputVal = Console.ReadLine();
- //string sql = "SELECT City from Customers WHERE CustomerID="+"'"+ Console.ReadLine()+ "'";
- string sql = "EXEC uspGetCity" + "'" + Console.ReadLine() + "'";
- var command = new SqlCommand(sql, cnn);
- var dataReader = command.ExecuteReader();
- while (dataReader.Read())
- {
- Console.WriteLine(dataReader.GetValue(0));
- }
- dataReader.Close();
- command.Dispose();
- cnn.Close();
- }
- catch (Exception ex)
- {
- Console.WriteLine("Can not open connection ! "+ex.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement