Hi, could I get a little help on this, I am not familiar with the whole idea. I am trying to take an Excel file and import it into a SQL 2000 database. This is what I have so far:
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim excelConnectionString As String = "Driver={Microsoft Excel Driver (*.xls)}; DBQ=C:\EditContract.xls"
Dim da As New OdbcDataAdapter("Select * from [Sheet1$]", New OdbcConnection(excelConnec
tionString
))Dim dt As New System.Data.DataTable()
da.Fill(dt)
Try
Dim sql1 As String = "insert into ContractTest (BranchID, CustomerNo, ContractNo) values(@BranchID, @CustomerNo, @ContractNo)"
Using conn As New SqlConnection(System.Confi
guration.C
onfigurati
onManager.
Connection
Strings("H
CISDataCon
nectionStr
ing").Conn
ectionStri
ng)
Dim cmd As New SqlCommand(sql1, conn)
cmd.Parameters.Add(New SqlParameter("@BranchID", ????))
cmd.Parameters.Add(New SqlParameter("@CustomerNo"
, ?????))
cmd.Parameters.Add(New SqlParameter("@ContractNo"
, ????))
conn.Open()
cmd.ExecuteNonQuery()
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Not sure if this is the correct approach or not, but that is what I was trying to do, not sure how to define the fields though.... I mean the @BranchID, ??? part or should I be doing that part differently??
Thanks,
Randy
Start Free Trial