예제 #1
0
        public Stock FindBySku(string sku)
        {
            Stock s = null;

            string sql = string.Format("SELECT * FROM Stock WHERE SKU = '{0}' ", sku);
            using (Connection cn = new Connection())
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    try
                    {
                        cmd.Connection = cn.SqlConnection;
                        cmd.CommandText = sql;
                        int recordsAffected = cmd.ExecuteNonQuery();
                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                s = new Stock();
                                s.StockID = (int)reader["StockID"];
                                s.StockGuid = (Guid)reader["StockGuid"];
                                s.SKU = reader["SKU"].ToString();
                                s.Description = reader["Description"].ToString();
                            }
                            return s;
                        }
                        else
                            return s;
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        return s;
                    }
                }
            }
        }