Exemple #1
0
        public void SaveUpdate()
        {
            d   = new BL.Dog();
            con = new SqlConnection(conString);
            con.Open();
            try
            {
                com = new SqlCommand(@"UPDATE tblDog SET  dogName='" + txtUpName + "',dogBreed='" + txtUpBreed + "',dogDOB='" + DateTime.Parse(txtUpDOB.Text) + "',dogGender='" + txtUpGender + "',dogFather='" + txtUpFather + "' ,dogMother='" + txtUpMother + "'WHERE (dogId='" + int.Parse(txtSearch.Text) + "')", con);

                com.ExecuteNonQuery();

                //d.DogName = txtUpName.Text;
                //d.DogBreed = txtUpBreed.Text;
                //d.DogDOB =  DateTime.Parse( txtUpDOB.Text);
                //d.DogFather = txtUpFather.Text;
                //d.DogGender = txtUpGender.Text;
                //d.DogMother = txtUpMother.Text;
                MessageBox.Show("Success");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            //  finally
            //{
            con.Close();
            // }
            //UpdateGUI();
        }
Exemple #2
0
        public int Search(int ID, BL.Dog Dog)
        {
            int  rc       = 0;
            bool dataRead = false;

            con = new SqlConnection(conString);

            try
            {
                con.Open();
                string strSQL = "SELECT * FROM tblDog WHERE DogId =" + ID;
                com = new SqlCommand(strSQL, con);

                IDataReader idr = com.ExecuteReader();
                dataRead = idr.Read();
                if (dataRead == false)
                {
                    rc = -1;
                }
                else
                {
                    while (dataRead)
                    {
                        d = new BL.Dog();
                        //  d.DogId = Convert.ToInt32(idr["DogId"]);
                        ID = Convert.ToInt32(idr["dogId"]);

                        d.DogName   = Convert.ToString(idr["dogName"]);
                        d.DogBreed  = Convert.ToString(idr["dogBreed"]);
                        d.DogDOB    = Convert.ToDateTime(idr["dogDOB"]);
                        d.DogGender = Convert.ToString(idr["DogGender"]);
                        d.DogFather = Convert.ToString(idr["dogFather"]);
                        d.DogMother = Convert.ToString(idr["dogMother"]);


                        DoID = Convert.ToInt32(idr["DogId"]);
                        /////////////////////////////////////

                        dataRead = idr.Read();
                    }
                }
                idr.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
            return(rc);
        }
Exemple #3
0
        public void Insert()
        {
            try
            {
                con = new SqlConnection(conString);
                con.Open();
                d = new BL.Dog();

                MemoryStream mains = new MemoryStream();
                imagePictureBox.Image.Save(mains, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] Pic_arr = new byte[mains.Length];
                mains.Position = 0;
                mains.Read(Pic_arr, 0, Pic_arr.Length);

                com = new SqlCommand("INSERT INTO tblDog (dogId, dogName, dogBreed, dogDOB, dogGender, dogFather, dogMother, Image) VALUES ('" + int.Parse(dogIdTextBox.Text) + "','" + dogNameTextBox.Text + "','" + dogBreedTextBox.Text + "','" + dogDOBDateTimePicker.Value + "','" + dogGenderTextBox.Text + "','" + dogFatherTextBox.Text + "','" + dogMotherTextBox.Text + "', @Image)", con);
                com.Parameters.AddWithValue("@Image", Pic_arr);
                com.ExecuteNonQuery();

                d.DogId = int.Parse(dogIdTextBox.Text);

                d.DogName   = dogNameTextBox.Text;
                d.DogBreed  = dogBreedTextBox.Text;
                d.DogDOB    = dogDOBDateTimePicker.Value;
                d.DogGender = dogGenderTextBox.Text;
                d.DogFather = dogFatherTextBox.Text;
                d.DogMother = dogMotherTextBox.Text;

                MessageBox.Show("Success");
                con.Close();
                dogIdTextBox.Clear();
                //  dogDOBDateTimePicker.Clear();
                dogNameTextBox.Clear();
                dogBreedTextBox.Clear();
                dogGenderTextBox.Clear();
                dogFatherTextBox.Clear();
                dogMotherTextBox.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }