DB connect

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();
}

return ADW;
}

catch (Exception ex)
{
//클라이언트에게 예외를 던진다.
//throw ex;
string Err = ex.ToString();

return “”;
}

finally
{
//conn.Close();
conn.Dispose();
}

}

  • hsc95pi

    데이타 리턴없는 경우 :
    cmd.ExecuteNonQuery();

    < -> cmd.ExecuteReader();