Advertisement

03.18.2008 at 06:29AM PDT, ID: 23250056
[x]
Attachment Details

Update / Insert SQL database with Excel file, using Visual Studio

Asked by ratkinso666 in Visual Studio .NET 2005, Microsoft Visual Basic.Net

Tags: microsoft, Visual Studio, 2005, VB

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(excelConnectionString))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.Configuration.ConfigurationManager.ConnectionStrings("HCISDataConnectionString").ConnectionString)
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
[+][-]03.18.2008 at 06:39AM PDT, ID: 21150781

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Studio .NET 2005, Microsoft Visual Basic.Net
Tags: microsoft, Visual Studio, 2005, VB
Sign Up Now!
Solution Provided By: Chandan_Gowda
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.18.2008 at 06:44AM PDT, ID: 21150831

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.18.2008 at 06:50AM PDT, ID: 21150898

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.18.2008 at 12:37PM PDT, ID: 21154941

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628