WelshyWizard
IS-IT--Management
Hi all,
I'm using Visual Studio 2003 and SQL Server 2000.
I am looking to insert the contents of a csv file into an existing SQL Server table. I would like to do this via VB.NET.
Could someone post some code to show me how to do this? Is it easier if I import the csv into a datagrid and then update the SQL table from there? If it is I already use the following code to populate a datagrid with the csv file.
How would I then get the datagrid contents into the table.
If this isn't the best way of going about it... what is?
Cheers
Today is the tomorrow you worried about yesterday - and all is well.....
I'm using Visual Studio 2003 and SQL Server 2000.
I am looking to insert the contents of a csv file into an existing SQL Server table. I would like to do this via VB.NET.
Could someone post some code to show me how to do this? Is it easier if I import the csv into a datagrid and then update the SQL table from there? If it is I already use the following code to populate a datagrid with the csv file.
Code:
If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
Dim fi As New FileInfo(OpenFileDialog1.FileName)
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName
Dim objConn As New OleDbConnection(sConnectionString)
objConn.Open()
Dim objCmdSelect As New OleDbCommand("SELECT * FROM " & fi.Name, objConn)
Dim objAdapter1 As New OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect
Dim objDataset1 As New DataSet
objAdapter1.Fill(objDataset1, "test")
DataGrid1.DataSource = objDataset1.Tables(0).DefaultView
objConn.Close()
End If
How would I then get the datagrid contents into the table.
If this isn't the best way of going about it... what is?
Cheers
Today is the tomorrow you worried about yesterday - and all is well.....