예제 #1
0
        public test Select(int id)
        {
            test          test             = new test();
            string        ConnectionString = IDManager.connection();
            SqlConnection con = new SqlConnection(ConnectionString);

            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("SP_DMCS_SELECT_TEST", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@id", id);
                SqlDataReader rdr = cmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    rdr.Read();
                    if (!rdr.IsDBNull(0))
                    {
                        test.id = rdr.GetInt32(0);
                    }
                    else
                    {
                        test.id = 0;
                    }
                    if (!rdr.IsDBNull(1))
                    {
                        test.firstName = rdr.GetString(1);
                    }
                    else
                    {
                        test.firstName = " ";
                    }
                    if (!rdr.IsDBNull(2))
                    {
                        test.lastName = rdr.GetString(2);
                    }
                    else
                    {
                        test.lastName = " ";
                    }
                }
                else
                {
                    test.SetColumnDefaults();
                }
            }
            catch (Exception ex)
            {
                test.SetColumnDefaults();
                return(test);
            }
            finally
            {
                con.Close();
            }
            return(test);
        }
예제 #2
0
        public test Insert(test id)
        {
            string        ConnectionString = IDManager.connection();
            SqlConnection con = new SqlConnection(ConnectionString);

            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("SP_DMCS_INSERT_TEST", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@firstName", id.firstName);
                cmd.Parameters.AddWithValue("@lastName", id.lastName);
                cmd.ExecuteReader();
                con.Close();
                con.Open();
                cmd             = new SqlCommand("SP_DMCS_GET_TEST", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@firstName", id.firstName);
                cmd.Parameters.AddWithValue("@lastName", id.lastName);
                SqlDataReader rdr = cmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    rdr.Read();
                    id.id = rdr.GetInt32(0);
                }
            }
            catch (Exception ex)
            {
                id.SetColumnDefaults();
            }
            finally
            {
                con.Close();
            }
            return(id);
        }
 public test Select(int id)
 {
     test test = new test();
     string ConnectionString = IDManager.connection();
     SqlConnection con = new SqlConnection(ConnectionString);
     try
     {
     con.Open();
     SqlCommand cmd = new SqlCommand("SP_DMCS_SELECT_TEST", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@id", id);
     SqlDataReader rdr = cmd.ExecuteReader();
     if (rdr.HasRows)
     {
         rdr.Read();
         if (!rdr.IsDBNull(0))
         {
             test.id = rdr.GetInt32(0);
         }
         else
         {
             test.id = 0;
         }
         if (!rdr.IsDBNull(1))
         {
             test.firstName = rdr.GetString(1);
         }
         else
         {
             test.firstName = " ";
         }
         if (!rdr.IsDBNull(2))
         {
             test.lastName = rdr.GetString(2);
         }
         else
         {
             test.lastName = " ";
         }
         }
         else
         {
             test.SetColumnDefaults();
         }
     }
     catch (Exception ex)
     {
     test.SetColumnDefaults();
     return test;
     }
     finally
     {
     con.Close();
     }
     return test;
 }
 public test Insert(test id)
 {
     string ConnectionString = IDManager.connection();
     SqlConnection con = new SqlConnection(ConnectionString);
     try
     {
     con.Open();
     SqlCommand cmd = new SqlCommand("SP_DMCS_INSERT_TEST", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@firstName", id.firstName);
     cmd.Parameters.AddWithValue("@lastName", id.lastName);
     cmd.ExecuteReader();
     con.Close();
     con.Open();
     cmd = new SqlCommand("SP_DMCS_GET_TEST", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@firstName", id.firstName);
     cmd.Parameters.AddWithValue("@lastName", id.lastName);
     SqlDataReader rdr = cmd.ExecuteReader();
     if (rdr.HasRows)
     {
         rdr.Read();
         id.id = rdr.GetInt32(0);
     }
     }
     catch (Exception ex)
     {
     id.SetColumnDefaults();
     }
     finally
     {
     con.Close();
     }
     return id;
 }