Example #1
0
        public void addCatalogPart(Catalog_partM CP)
        {
            string spName = @"[dbo].[addCatalogPart]";

            using (SqlCommand cmd = new SqlCommand(spName, SQLConnection))
            {
                SqlParameter[] parms = new SqlParameter[1];
                string[]       names =
                {
                    "@Part_name"
                };
                SqlDbType[] DBtypes =
                {
                    SqlDbType.VarChar
                };
                Object[] values =
                {
                    CP.Part_name
                };
                for (int i = 0; i < parms.Length; i++)
                {
                    parms[i] = new SqlParameter();
                    parms[i].ParameterName = names[i];
                    parms[i].SqlDbType     = DBtypes[i];
                    parms[i].Value         = values[i];
                    cmd.Parameters.Add(parms[i]);
                }
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.ExecuteNonQuery();
            }
        }
Example #2
0
        public Catalog_partM getCatalogPart(int Part_id)
        {
            Catalog_partM CatalogPart = null;
            string        spName      = @"[dbo].[getCatalogPart]";

            using (SqlCommand cmd = new SqlCommand(spName, SQLConnection))
            {
                SqlParameter part_id_Parameter = new SqlParameter();
                part_id_Parameter.ParameterName = "@Part_id";
                part_id_Parameter.SqlDbType     = SqlDbType.Int;
                part_id_Parameter.Value         = Part_id;
                cmd.Parameters.Add(part_id_Parameter);
                cmd.CommandType = CommandType.StoredProcedure;
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        int test = 0;
                        while (reader.Read())
                        {
                            if (test > 0)
                            {
                                throw new Exception("more then one part with the PK: " + Part_id + ", key values have been destroyed");
                            }
                            CatalogPart = new Catalog_partM(reader);
                        }
                    }
                }
            }
            return(CatalogPart);
        }