I wrote the following code to do this:

1) read a table inside an Access .mdb file
2) format the data to match the formatting on a SQL 2000 db
3) write the newly formatted data into the SQL 2000 db

there are four control not shown here: sqlConnection, sqlCommand, oleDBConnection, oleDBCommand.

The code works but I was wondering if there was a more efficient way of doing it. maybe with datasets and the such?

in particular: could (should) I have used Datasets? the arrays---whats a better way? I KNEW ahead of time there were just under 1000 rows. What if the row count is unknown?

Thanks ahead everyone!!



VB Code:
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         AccessConn.Open()
  3.  
  4.         Dim reader As OleDb.OleDbDataReader
  5.  
  6.         reader = AccessCMD.ExecuteReader
  7.  
  8.         Dim strTmp As String
  9.         Dim artist(1000) As String
  10.         Dim song(1000) As String
  11.         Dim mag(1000) As String
  12.         Dim month(1000) As String
  13.         Dim year(1000) As String
  14.  
  15.         Dim intCount As Integer = 0
  16.  
  17.         While reader.Read()
  18.  
  19.             artist(intCount) = reader.Item("Artists")
  20.             artist(intCount) = artist(intCount).Replace("'", "º")
  21.  
  22.             song(intCount) = reader.Item("Song")
  23.             song(intCount) = song(intCount).Replace("'"c, "º"c)
  24.  
  25.             mag(intCount) = reader.Item("Magazine")
  26.  
  27.             strTmp = reader.Item("Month/Year")
  28.  
  29.             If strTmp = "1995" Then
  30.                 strTmp = "Jan/1995"
  31.             End If
  32.  
  33.             year(intCount) = strTmp.Substring(strTmp.IndexOf("/") + 1)
  34.  
  35.             month(intCount) = strTmp.Substring(0, strTmp.IndexOf("/"))
  36.  
  37.             Select Case month(intCount)
  38.  
  39.                 Case "Jan"
  40.                     month(intCount) = "January"
  41.                 Case "Feb"
  42.                     month(intCount) = "February"
  43.                 Case "Mar"
  44.                     month(intCount) = "March"
  45.                 Case "Apr"
  46.                     month(intCount) = "April"
  47.                 Case "May"
  48.                     month(intCount) = "May"
  49.                 Case "Jun"
  50.                     month(intCount) = "June"
  51.                 Case "Jul"
  52.                     month(intCount) = "July"
  53.                 Case "Aug"
  54.                     month(intCount) = "August"
  55.                 Case "Sep"
  56.                     month(intCount) = "September"
  57.                 Case "Oct"
  58.                     month(intCount) = "October"
  59.                 Case "Nov"
  60.                     month(intCount) = "November"
  61.                 Case "Dec"
  62.                     month(intCount) = "December"
  63.  
  64.             End Select
  65.  
  66.             Select Case mag(intCount)
  67.                 Case "Guitar(fpm)"
  68.                     mag(intCount) = "Gftpm"
  69.             End Select
  70.  
  71.             intCount += 1
  72.  
  73.         End While
  74.  
  75.         reader.Close()
  76.         AccessConn.Close()
  77.  
  78.         SqlConn.Open()
  79.  
  80.         For c As Integer = 0 To intCount
  81.  
  82.             SqlCMD.CommandText = "Insert Into Tabs " & _
  83.                 "(Artist, Song, Magazine, Month, Year) Values('" & _
  84.                 artist(c) & "', '" & song(c) & "', '" & mag(c) & _
  85.                 "', '" & month(c) & "', '" & year(c) & "')"
  86.  
  87.             SqlCMD.ExecuteNonQuery()
  88.  
  89.         Next
  90.  
  91.         MessageBox.Show("Done")
  92.  
  93.     End Sub