Академический Документы
Профессиональный Документы
Культура Документы
Go to start menu and search “Microsoft Access”. Then select it from the
list.
HOW TO CREATE MICROSOFT ACCESS DATABASE AND TABLE
VIDEO TUTORIAL
VIDEO TUTORIAL
Choose Browse next to Database file name, and then navigate to your
.accdb file and choose Open.
How To Add Ms Access Database To Visual Studio 2010 – Choose Browse next to Database file
name
Browse the file name. This is the location where your database is
stored. i.e. – (C:\Users\Authentic\Documents\Database1.accdb).
How To Add Ms Access Database To Visual Studio 2010 – Connection String Database File Name
Now go to server explorer window and you will see the newly added
database.
How To Add Ms Access Database To Visual Studio 2010 – Microsoft Access Database Added To
Project Server Explorer
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #3 – How To Add Ms Access Database To Visual Studio 2010
(.accdb file)
VIDEO TUTORIAL
When the data is inserted you get a dialog box informing you that the
data has been added to ms-access database successfully.
How To Insert Data Into Ms Access Database Using C Sharp And Display In Datagridview
When you click OK button on the message box, the box closes and
datagridview refreshes with a new inserted row at the bottom.
How To Display Data In Datagridview From Access Database C Sharp
All fields are inserted to ms access database at once when you click
insert button. The image from picturebox is added to the database as
byte array. The Id Column, Which is the first one, Is Auto Incremented
whenever you insert a new row to the database.
CODE SNIPPET C#
1 //Inserting data into microsoft access database
?
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #5 – How To Insert Data And Images Into Microsoft Access
Database
CODE SNIPPET C#
1 //Function for retrieving data from ms access ?d
2 public void populateDataGridView()
3 {
4 //First, clear all rows before populating d
5 if (dataGridView1.Rows.Count > 0)
6 {
7 dataGridView1.Rows.Clear();
8 }
9
10 try
11 {
12 accessDatabaseConnection.Open();
13 //OleDbDataAdapter adapter = new OleDbD
14 OleDbCommand command = new OleDbCommand
15 OleDbDataReader reader = command.Execut
16
17 while (reader.Read())
18 {
19 //Console.WriteLine(reader[8].GetTy
20 dataGridView1.Rows.Add(reader[0].To
21 }
22
23 reader.Close();
24 }
25 catch (Exception ex)
26 {
27 MessageBox.Show(ex.StackTrace);
28 }
29 finally
30 {
31 //Finally Close MS Access Database Conn
32 if (accessDatabaseConnection != null)
33 {
34 accessDatabaseConnection.Close();
35 }
36
37
38 }
39 }
VIDEO TUTORIAL
The data is updated based on the selected datagridview row ID. To use
update feature click on datagridview row, And the input fields gets filled
with selected datagridview row data. Then change few fields and click
update button.
CODE SNIPPET C#
1 //Update data in microsoft access database and?
2 private void button1_Click(object sender, Event
3 {
4 if (txtID.Text == String.Empty)
5 {
6 MessageBox.Show("First Click On Datagri
7 }
8 else
9 {
10 try
11 {
12 //Check If One Or More Fields Are E
13 if (txtFullName.Text == String.Empt
14 {
15 MessageBox.Show("One Or More Em
16 }
17 else
18 {
19 OleDbCommand updateDataInMSAcce
20 updateDataInMSAccessDatabaseOle
21 updateDataInMSAccessDatabaseOle
22 updateDataInMSAccessDatabaseOle
23 updateDataInMSAccessDatabaseOle
24 updateDataInMSAccessDatabaseOle
25 updateDataInMSAccessDatabaseOle
26 updateDataInMSAccessDatabaseOle
27 updateDataInMSAccessDatabaseOle
28 updateDataInMSAccessDatabaseOle
29 //Opening Access Database Conne
30 accessDatabaseConnection.Open()
31 int insertDataToAccessDatabase
32 //If data Has been inserted to
33 if (insertDataToAccessDatabase
34 {
35 MessageBox.Show("Data Updat
36 //Clear Input fields After
37 clearInputFields();
38 }
39 }
40
41 }
42 catch (Exception ex)
43 {
44 MessageBox.Show(ex.StackTrace);
45 }
46 finally
47 {
48 //Finally Close MS Access Database
49 if (accessDatabaseConnection != nul
50 {
51 accessDatabaseConnection.Close
52 }
53 }
54 //Refreshing Datagridview after Updatin
55 populateDataGridView();
56 }
57
58 }
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #7 – How To Update Selected Datagridview Row With Textbox
And Picture Box
Deleting Selected Rows From Datagridview
And Microsoft Access Database In C#
Visual Studio
Then a Message Box Appears showing that the selected row has been
deleted successfully.
How To Delete Record From Ms-access Database And Datagridview In C Sharp Windows Application
The Row Gets deleted when you click Delete button. This removes
selected row from both MS Access Database and Datagridview.
CODE SNIPPET C#
1 //Delete From Microsoft access Database ?
VIDEO TUTORIAL
CODE SNIPPET C#
1 //Function For Converting Image To Byte Array ?
2 public byte[] convertImageToByteArray(Image img)
3 {
4 MemoryStream ms = new MemoryStream();
5 img.Save(ms, img.RawFormat);
6 return ms.ToArray();
7 }
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #9 - …
Watch later Share
Images are converted from byte array to Image before displaying them
on picturebox from ms-access database.
CODE SNIPPET C#
1 //Function for Converting Byte Array To Image ?
2 public Image convertByteArrayToImage(byte[] img)
3 {
4 MemoryStream ms = new MemoryStream(img);
5
6 return Image.FromStream(ms);
7
8 }
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #10 – How To Convert Byte Array To Image
When you click choose image button the Dialog open giving you an
option to choose image from your computer. When you choose image
and click open button the image is displayed on PictureBox ready to be
inserted into the database. Also full image path is displayed in the
appropriate TextBox.
CODE SNIPPET C#
1 //Display image on picture box on button click?
2 private void btnChooseImage_Click(object sender
3 {
4 OpenFileDialog chooseImage = new OpenFileDi
5 chooseImage.Title = "Choose Image";
6 DialogResult chooseImageDialog = chooseImag
7
8 if (chooseImageDialog == DialogResult.OK)
9 {
10 txtImagePath.Text = chooseImage.FileNam
11 //Displaying image from Pc On PictureBo
12 pictureBox1.Image = Image.FromFile(choo
13 }
14 }
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #11 – How To Choose Image From Computer And Display It On
Picturebox
CODE SNIPPET C#
1 private void dataGridView1_CellContentClick(obj
?
2 {
3 //Check if the row cell content is clicked
4 if (e.RowIndex >= 0)
5 {
6 DataGridViewRow datagridviewrow = dataG
7 //Assigning Textboxes and picturebox wi
8 txtID.Text = datagridviewrow.Cells[0].V
9 txtFullName.Text = datagridviewrow.Cell
10 txtEmail.Text = datagridviewrow.Cells[2
11 txtPhoneNumber.Text = datagridviewrow.C
12 txtLanguage.Text = datagridviewrow.Cell
13 txtCountry.Text = datagridviewrow.Cells
14 txtGender.Text = datagridviewrow.Cells
15 txtImagePath.Text = datagridviewrow.Cel
16 //First cast image from datagridview ce
17 pictureBox1.Image = convertByteArrayToI
18 }
19 }
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #12 – How To Display Selected Row From Datagridview To
Textboxes On Cell Click
First i had to cast the image from datagridview cell to byte array and
then converted it to Image and finally assigned it to picturebox.Image
Value.
CODE SNIPPET C#
1 private void dataGridView1_CellContentClick(obj
?
2 {
3 //Check if the row cell content is clicked
4 if (e.RowIndex >= 0)
5 {
6 DataGridViewRow datagridviewrow = dataG
7
8 //First cast image from datagridview ce
9 pictureBox1.Image = convertByteArrayToI
10 }
11 }
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #13 – How To Display Selected Row From Datagridview To
Picturebox Cell Click
All input fields(textboxes, picturebox) gets cleared when you click Clear
button.
CODE SNIPPET C#
1 public void clearInputFields() ?
2 {
3 //Clearing Textfields
4 txtID.Text = String.Empty;
5 txtFullName.Text = String.Empty;
6 txtEmail.Text = String.Empty;
7 txtPhoneNumber.Text = String.Empty;
8 txtLanguage.Text = String.Empty;
9 txtCountry.Text = String.Empty;
10 txtGender.Text = String.Empty;
11 txtImagePath.Text = String.Empty;
12 //Clearing pictureBox
13 pictureBox1.Image = null;
14 }
15
16 private void btnClear_Click(object sender, Even
17 {
18 clearInputFields()
19 }
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #14 – How To Clear Input Fields Text Boxes And Picture Box
ADDING
MICROSOFT.OFFICE.INTEROP.EXCEL
REFERENCE IN VISUAL STUDIO 2010
Right-click on “References” and select “Add Reference”.
Adding Microsoft Office Interop Excel – Right-click on References and select Add Reference
Click Ok.
VIDEO TUTORIAL
CODE SNIPPET C#
1 //Exporting DataGridView To Excel ?
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #17 – How To Export Datagridview To Excel File In C# Windows
Application
IMPORTING DATA FROM EXCEL TO
DATAGRIDVIEW IN C#
Excel File gets imported to datagridview when you click Import Button.
You can clear datagridview rows before importing to see this feature in
Action.
CODE SNIPPET C#
1 //Import Data From Excel To DataGridView ?
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #16 – How To Import Excel File To Datagridview In C#
Windows Application
PRINTING DATAGRIDVIEW IN C# BY
CLICKING ON PRINT BUTTON
CODE SNIPPET C#
1 private void printDocument1_PrintPage(object se
?
2 {
3 Bitmap bm = new Bitmap(this.dataGridView1.W
4 dataGridView1.DrawToBitmap(bm, new System.D
5 e.Graphics.DrawImage(bm, 0, 0);
6 }
7
8 private void btnPrintDataGridView_Click(object
9 {
10 //Open the print dialog
11 PrintDialog printDialog = new PrintDialog()
12 printDialog.Document = printDocument1;
13 printDialog.UseEXDialog = true;
14 //Print document
15 if (DialogResult.OK == printDialog.ShowDial
16 {
17 //Document Name
18 printDocument1.DocumentName = "Printing
19 //Print Function
20 printDocument1.Print();
21 MessageBox.Show("Document Printed!!!..
22 }
23 }
VIDEO TUTORIAL
CODE SNIPPET C#
1 //Clearing DataGridView ?
VIDEO TUTORIAL
C# And Ms Access Database Tutorial #19 – How To Clear Datagridview In C# Windows Application
REFRESHING DATAGRIDVIEW IN C#
WINDOWS APPLICATION
CODE SNIPPET C#
1 private void btnRefreshDataGridView_Click(object
?
2 {
3 populateDataGridView();
4 }
VIDEO TUTORIAL
CODE SNIPPET C#
1 //Show Datagridview Selected Row Data In Anothe
?
C# And Ms Access Database Tutorial #21 – How To Show Datagridview Selected Row Data In
Another Form Using C#
C# And Ms Access Database Tutorial #22 – How To Show Datagridview Selected Rows To Another
Forms Datagridview Using C#
DEMO VIDEO
Published by admin
Prev Next
Solved!! Can’t read from the source file How To Add And Use Images From
or disk. [Problem Fixed] Resources In C Sharp Using Visual
Studio 2010
Leave a Reply
Your email address will not be published. Required fields are marked *
Comment
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
POST COMMENT
PDFmyURL.com - convert URLs, web pages or even full websites to PDF online. Easy API for developers!