コード例 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtAdd.Text == "")
            {
                txtAdd.BackColor = Color.Red;
                MessageBox.Show(this,
                                "Invalid Data ",
                                "Exit",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);


                txtAdd.Focus();
                txtAdd.BackColor = Color.White;
                return;
            }

            try
            {
                if (MessageBox.Show("Are you sure you want to Save this item?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    sqlcon.Open();
                    cm = new SqlCommand("INSERT  INTo tblBrand(Brand)VALUEs(@brand)", sqlcon);
                    cm.Parameters.AddWithValue("@brand", txtAdd.Text);
                    cm.ExecuteNonQuery();
                    sqlcon.Close();
                    MessageBox.Show("Record has benn Saved!");
                    Clear();
                    frmlsit.loadRecord();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }