Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in this code the message box is show that data has been successfully saved but in databse there no showing of data .



C#
namespace Login_Form
{
   public partial class frmCreateCompany : Form
   {
      SqlConnection con = null;
      SqlDataAdapter adp;
      DataSet ds = new DataSet();
      SqlCommand cmd = null;
      DataTable dt = new DataTable();

      public frmCreateCompany()
      {
         InitializeComponent();
      }
      private void Form1_Load(object sender, EventArgs e)
      {
            
      }
      private void button4_Click(object sender, EventArgs e)
      {
         SqlConnection con = new SqlConnection("Data Source=.\\SqlExpress; Integrated Security=True; AttachDbFilename=|DataDirectory|\\Garment.mdf; User Instance=true;");
         con.Open();

         if (textBox2.Text == "")
         {
            MessageBox.Show("Please enter Company Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox2.Focus();
            return;
         }
         if (textBox3.Text == "")
         {
            MessageBox.Show("Please enter Mailing  Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox3.Focus();
            return;
         }
         if (textBox4.Text == "")
         {
            MessageBox.Show("Please enter License Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox4.Focus();
            return;
         }
         if (textBox5.Text == "")
         {
            MessageBox.Show("Please enter Post Offcie Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox5.Focus();
            return;
         }
         if (textBox6.Text == "")
         {
            MessageBox.Show("Please enter Location", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox6.Focus();
            return;
         }
         if (textBox7.Text == "")
         {
            MessageBox.Show("Please enter State", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox7.Focus();
            return;
         }
         if (textBox8.Text == "")
         {
            MessageBox.Show("Please enter Country", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox8.Focus();
             return;
         }
         if (textBox9.Text == "")
         {
            MessageBox.Show("Please enter Telephone Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox9.Focus();
            return;
         }
         if (textBox10.Text == "")
         {
            MessageBox.Show("Please enter Fax No.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox10.Focus();
            return;
         }
         if (textBox11.Text == "")
         {
            MessageBox.Show("Please enter Email id", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox11.Focus();
            return;
         }
         if (textBox12.Text == "")
         {
            MessageBox.Show("Please enter Website Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox12.Focus();
            return;
         }
         if (textBox13.Text == "")
         {
            MessageBox.Show("Please enter Currency Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            textBox13.Focus();
            return;
         }
         if (AccountingStart.Text == "")
         {
            MessageBox.Show("Please Select Start date ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            AccountingStart.Focus();
            return;
         }
         if (AccountingFrom.Text == "")
         {
            MessageBox.Show("Please Select End date ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            AccountingFrom.Focus();
            return;
         }

         try
         {
            //con = new SqlConnection(cs);
            //con.Open();
            string cb = "INSERT INTO COMPANY_MASTER(C_Name,M_Name,L_No,Tax_No,PO_No,Location,State,Country,Telephone,Fax_No,Email_Id,Website,Currency_Name,Company_logo,APT,APF) VALUES(@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16)";
            cmd = new SqlCommand(cb);
            cmd.Connection = con;
            cmd.Parameters.Add(new SqlParameter("@d1", System.Data.SqlDbType.NChar, 10, "C_Name"));
            cmd.Parameters.Add(new SqlParameter("@d2", System.Data.SqlDbType.NChar, 10, "M_Name"));
            cmd.Parameters.Add(new SqlParameter("@d3", System.Data.SqlDbType.NChar, 10, "L_No"));
            cmd.Parameters.Add(new SqlParameter("@d4", System.Data.SqlDbType.NChar, 10, "Tax_No"));
            cmd.Parameters.Add(new SqlParameter("@d5", System.Data.SqlDbType.NChar, 10, "PO_No"));
            cmd.Parameters.Add(new SqlParameter("@d6", System.Data.SqlDbType.NChar, 10, "Location"));
            cmd.Parameters.Add(new SqlParameter("@d7", System.Data.SqlDbType.NChar, 10, "State"));
            cmd.Parameters.Add(new SqlParameter("@d8", System.Data.SqlDbType.NChar, 10, "Country"));
            cmd.Parameters.Add(new SqlParameter("@d9", System.Data.SqlDbType.NChar, 10, "Telephone"));
            cmd.Parameters.Add(new SqlParameter("@d10", System.Data.SqlDbType.NChar, 10, "Fax_No"));
            cmd.Parameters.Add(new SqlParameter("@d11", System.Data.SqlDbType.NChar, 10, "email_Id"));
            cmd.Parameters.Add(new SqlParameter("@d12", System.Data.SqlDbType.NChar, 10, "Website"));
            cmd.Parameters.Add(new SqlParameter("@d13", System.Data.SqlDbType.NChar, 10, "Currency_Name"));
            MemoryStream ms = new MemoryStream();
            Bitmap bmpImage = new Bitmap(pictureBox1.Image);
            bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

            byte[] data = ms.GetBuffer();
            SqlParameter p = new SqlParameter("@d14", SqlDbType.Image);
            p.Value = data;
            cmd.Parameters.Add(p);
            cmd.Parameters.Add(new SqlParameter("@d15", System.Data.SqlDbType.Date, 30, "APT"));
            cmd.Parameters.Add(new SqlParameter("@d16", System.Data.SqlDbType.Date, 30, "APF"));

            cmd.Parameters["@d1"].Value = textBox2.Text.Trim();
            cmd.Parameters["@d2"].Value = textBox3.Text.Trim();
            cmd.Parameters["@d3"].Value = textBox4.Text.Trim();
            cmd.Parameters["@d4"].Value = textBox5.Text.Trim();
            cmd.Parameters["@d5"].Value = textBox6.Text.Trim();
            cmd.Parameters["@d6"].Value = textBox7.Text.Trim();
            cmd.Parameters["@d7"].Value = textBox8.Text.Trim();
            cmd.Parameters["@d8"].Value = textBox9.Text.Trim();
            cmd.Parameters["@d9"].Value = textBox10.Text.Trim();
            cmd.Parameters["@d10"].Value = textBox11.Text.Trim();
            cmd.Parameters["@d11"].Value = textBox12.Text.Trim();
            cmd.Parameters["@d12"].Value = textBox13.Text.Trim();
            cmd.Parameters["@d13"].Value = textBox14.Text.Trim();
            cmd.Parameters["@d14"].Value = p.Value;

            cmd.Parameters["@d15"].Value = AccountingStart.Text.Trim();
            cmd.Parameters["@d16"].Value = AccountingFrom.Text.Trim();

            cmd.ExecuteNonQuery();
            //cmd.ExecuteReader();

            con.Close();
            MessageBox.Show("Successfully saved ", "Company", MessageBoxButtons.OK, MessageBoxIcon.Information);

         }
         catch (Exception ex)
         {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
      }

      private void button1_Click(object sender, EventArgs e)
      {
         var _with1 = openFileDialog1;

         _with1.Filter = ("Images |*.png; *.bmp; *.jpg;*.jpeg; *.gif; *.ico");
         _with1.FilterIndex = 4;

         //Reset the file name
         openFileDialog1.FileName = "";

         if (openFileDialog1.ShowDialog() == DialogResult.OK)
         {
            pictureBox1.Image=Image.FromFile(openFileDialog1.FileName);
         }
      }
   }
}
Posted
Updated 23-Apr-14 0:14am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900