C Sharp And Ms Access Database Tutorial 5 How To Insert Data And Images Into Microsoft Access Database

C# And Ms Access Database Tutorial #5 – How To Insert Data And Images Into Microsoft Access Database

VIDEO TUTORIAL

C# And Ms Access Database Tutorial #5 – How To Insert Data And Images Into Microsoft Access Database

This Tutorial Shows How To Insert Data And Images Into Microsoft Access Database In C# Windows Forms Application using visual studio 2010.

How To Insert Data And Images Into Microsoft Access Database
How To Insert Data And Images Into Microsoft Access Database
How To Insert Data And Images Into Microsoft Access Database - DB
How To Insert Data And Images Into Microsoft Access Database – DB

C# SOURCE CODE

        private void button2_Click_1(object sender, EventArgs e)
        {
            OleDbCommand InsertDataIntoMicrosoftAccessDatabaseOleDbCommand;

            //Check If One Or More Fields Are Empty

            if (String.IsNullOrEmpty(txtFullName.Text) || String.IsNullOrEmpty(txtEmailAddess.Text) || String.IsNullOrEmpty(txtPhoneNumber.Text) || String.IsNullOrEmpty(txtLanguage.Text) || String.IsNullOrEmpty(txtCountry.Text) || String.IsNullOrEmpty(txtgender.Text) || String.IsNullOrEmpty(txtImagePath.Text) || pictureBox1.Image == null)
            {
                MessageBox.Show("One Or More Fields Are Empty Make Sure All Fields Are Filled......");
            }
            else
            {
                try
                {
                    InsertDataIntoMicrosoftAccessDatabaseOleDbCommand = new OleDbCommand(insertDataIntoMicrosoftAccessDatabase, microsoftAccessDatabaseOleDbConnection);
                    InsertDataIntoMicrosoftAccessDatabaseOleDbCommand.Parameters.AddWithValue("FullName", OleDbType.VarChar).Value = txtFullName.Text;
                    InsertDataIntoMicrosoftAccessDatabaseOleDbCommand.Parameters.AddWithValue("EmailAddress", OleDbType.VarChar).Value = txtEmailAddess.Text;
                    InsertDataIntoMicrosoftAccessDatabaseOleDbCommand.Parameters.AddWithValue("PhoneNumber", OleDbType.VarChar).Value = txtPhoneNumber.Text;
                    InsertDataIntoMicrosoftAccessDatabaseOleDbCommand.Parameters.AddWithValue("LanguageP", OleDbType.VarChar).Value = txtLanguage.Text;
                    InsertDataIntoMicrosoftAccessDatabaseOleDbCommand.Parameters.AddWithValue("CountryP", OleDbType.VarChar).Value = txtCountry.Text;
                    InsertDataIntoMicrosoftAccessDatabaseOleDbCommand.Parameters.AddWithValue("GenderP", OleDbType.VarChar).Value = txtgender.Text;
                    InsertDataIntoMicrosoftAccessDatabaseOleDbCommand.Parameters.AddWithValue("ImagePath", OleDbType.VarChar).Value = txtImagePath.Text;
                    InsertDataIntoMicrosoftAccessDatabaseOleDbCommand.Parameters.AddWithValue("ImageFile", OleDbType.Binary).Value = convertImageToByteArray(pictureBox1.Image);
                    //Open Microsoft Access Database Connection
                    openConnection();
                    int dataInserted = InsertDataIntoMicrosoftAccessDatabaseOleDbCommand.ExecuteNonQuery();

                    if (dataInserted > 0)
                    {
                        MessageBox.Show("Data Inserted To Microsoft Access Database Successfully.................");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    //finally close Connection To Microsoft Access Database
                    closeConnection();
                }
            }
        }
READ MORE  How To Change Display Refresh Rate Windows 10 - Adjust Screen Refresh Rate

Leave a Reply

Your email address will not be published. Required fields are marked *