1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
class DBData { static string connectionString = "server= localhost;uid=user;pwd=pass;database=SSC"; public static string Select(int Sending_SSC) { string ADW = null; //SQL 연결설정 //Call stored procedure with parameter and return value SqlConnection conn = new SqlConnection(connectionString); try { conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "GetCachingADW"; SqlParameter paramSending_SSC = cmd.Parameters.Add("@Sending_SSC",SqlDbType.SmallInt); paramSending_SSC.Direction = ParameterDirection.Input; paramSending_SSC.Value = Sending_SSC; SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { ADW = reader["ADW"].ToString(); } reader.Close(); // <- too easy to forget reader.Dispose(); // <- too easy to forget conn.Close(); // <- too easy to forget return ADW; } catch (Exception ex) { //클라이언트에게 예외를 던진다. //throw ex; string Err = ex.ToString(); return ""; } } |