I am looking at Visual Basic 2008 Step By Step. I need to read a flat file and insert the records into my SQL database. My code so far:
The INPUT line needs to be fixed. From what I can see, I need to move it all to a single field and use a split to parse it, correct?Code:'NEXT, ADD RECORDS TO PAYROLLMASTER FileOpen(1, "z:\PR\PAYROLLMASTER.csv", OpenMode.Input) Do Until EOF(1) Input #1, EMPLOYEEID, LASTNAME, FIRSTNAME, MIDDLENAME, SSN '============================================= Dim cnxn2 As SqlClient.SqlConnection cnxn2 = New SqlClient.SqlConnection(cnxnstring) cnxn2.Open() Dim sqlInsert As New SqlClient.SqlCommand sqlInsert.CommandText = "INSERT INTO PAYROLLMASTER ([EMPLOYEEID],[LASTNAME],[FIRSTNAME],[MIDDLENAME],[SSN]) " sqlInsert.CommandText += "VALUES(@employeeid,@lastname,@firstname,@middlename,@ssn)" sqlInsert.Parameters.AddWithValue("@employeeid", EMPLOYEEID) sqlInsert.Parameters.AddWithValue("@lastname", LASTNAME) sqlInsert.Parameters.AddWithValue("@firstname", FIRSTNAME) sqlInsert.Parameters.AddWithValue("@middlename", MIDDLENAME) sqlInsert.Parameters.AddWithValue("@ssn", SSN) sqlInsert.ExecuteNonQuery() sqlInsert.Dispose() cnxn2.Close() cnxn2.Dispose() '============= Loop FileClose(1)
As I look at the entries on this site, all the code seems to use stream readers. Why would the book not do that? Am I missing something?




Reply With Quote