C
cj
I have to take an excel sheet and for each of the 40,000 some customer
records look up their address from a Sql Server database using their
customer number found in the first column of the excel table and add the
address columns addr1, addr2, city, state, zip to the end of the excel
table records so I can return the spreadsheet to accounting. I'm
thinking I like the approach of accessing the excel sheet via oledb
database like below. I don't need to display it in the datagrid in the
final program I was just making sure I had the data loaded into a
datatable. Actually I don't know that I need the datatable. How do I
loop through this oledb table record by record? How do I add fields to
the end of the records once I've found the address? Do I need to add
columns to the spreadsheet ahead of time for the address data? Any
ideas would be appreciated. I'll post this while I continue to try to
figure it out.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Button1.Enabled = False
MyOpenFileDialog = New OpenFileDialog
MyOpenFileDialog.Title = "Open Excel file"
MyOpenFileDialog.FileName = ""
MyOpenFileDialog.InitialDirectory = "c:\"
MyOpenFileDialog.DefaultExt = ".XLS"
MyOpenFileDialog.Filter = "XLS files (*.XLS)|*.XLS|All files
(*.*)|*.*"
MyOpenFileDialog.RestoreDirectory = True
If MyOpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim filename As String = MyOpenFileDialog.FileName
Dim mydt As New System.Data.DataTable
Dim myExcelConnection As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" & filename & "; Extended Properties=""Excel 8.0""")
Dim myExcelSqlCommand As String = "SELECT * FROM [" & "all
ANIs" & "$]"
Dim myExcelAdapter = New
System.Data.OleDb.OleDbDataAdapter(myExcelSqlCommand, myExcelConnection)
myExcelAdapter.fill(mydt)
DataGridView1.DataSource = mydt
End If
Button1.Enabled = True
End Sub
records look up their address from a Sql Server database using their
customer number found in the first column of the excel table and add the
address columns addr1, addr2, city, state, zip to the end of the excel
table records so I can return the spreadsheet to accounting. I'm
thinking I like the approach of accessing the excel sheet via oledb
database like below. I don't need to display it in the datagrid in the
final program I was just making sure I had the data loaded into a
datatable. Actually I don't know that I need the datatable. How do I
loop through this oledb table record by record? How do I add fields to
the end of the records once I've found the address? Do I need to add
columns to the spreadsheet ahead of time for the address data? Any
ideas would be appreciated. I'll post this while I continue to try to
figure it out.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Button1.Enabled = False
MyOpenFileDialog = New OpenFileDialog
MyOpenFileDialog.Title = "Open Excel file"
MyOpenFileDialog.FileName = ""
MyOpenFileDialog.InitialDirectory = "c:\"
MyOpenFileDialog.DefaultExt = ".XLS"
MyOpenFileDialog.Filter = "XLS files (*.XLS)|*.XLS|All files
(*.*)|*.*"
MyOpenFileDialog.RestoreDirectory = True
If MyOpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim filename As String = MyOpenFileDialog.FileName
Dim mydt As New System.Data.DataTable
Dim myExcelConnection As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" & filename & "; Extended Properties=""Excel 8.0""")
Dim myExcelSqlCommand As String = "SELECT * FROM [" & "all
ANIs" & "$]"
Dim myExcelAdapter = New
System.Data.OleDb.OleDbDataAdapter(myExcelSqlCommand, myExcelConnection)
myExcelAdapter.fill(mydt)
DataGridView1.DataSource = mydt
End If
Button1.Enabled = True
End Sub