Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB.NET
Private Sub btnSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectAll.Click

        DataGridView1.SelectAll()

    End Sub





//for the saving process
st = "INSERT INTO [Students](ID, Students, Course, Major_in, Yr_Sec, Sec, College, F_name, M_name, L_name )VALUES ('" & Me.DataGridView1.SelectedCells(0).Value & "','" & Me.DataGridView1.SelectedCells(1).Value & "','" & Me.DataGridView1.SelectedCells(2).Value & "','" & Me.DataGridView1.SelectedCells(3).Value & "','" & Me.DataGridView1.SelectedCells(4).Value & "','" & Me.DataGridView1.SelectedCells(5).Value & "','" & Me.DataGridView1.SelectedCells(6).Value & "','" & Me.DataGridView1.SelectedCells(7).Value & "','" & Me.DataGridView1.SelectedCells(8).Value & "','" & Me.DataGridView1.SelectedCells(9).Value & "')"
Posted
Updated 17-Jan-16 14:02pm
v2

If you're going to select everything in the datagrid, why select it at all? Just go to exporting the contents to Excel.

Google for "VB.NET sql parameterized queries" and forget building an SQL statement using string concatenation. You'll be much better off against SQL inject attacks and you will also not have to deal with apostrophe characters in the data screwing up your SQL statements.
 
Share this answer
 
Just iterate the INSERT for each row.
Check following article for better understanding-
Insert (Save) Multiple rows from DataGridView to Database in Windows Forms (WinForms) Application using C# and VB.Net[^]
Only you have to change is the connection from SQL Server to MS Access.
Following article may help you on that regard-
Insert, Update, Delete & Search Values in MS Access 2003 with VB.NET 2005[^]

If you still find problem to implement all these, please let me know.

Hope, it helps :)
 
Share this answer
 

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