Wrox Programmer Forums
|
Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 5th, 2010, 01:19 AM
Authorized User
 
Join Date: Dec 2009
Posts: 69
Thanks: 6
Thanked 0 Times in 0 Posts
Default Connecting to Excel

I am trying to connect to Excel using OleDb, and insert a line of data through a form named "ProjFeed" that the user will input his data. Initially, I had a lot of errors but managed to fix them all. I then every time I run my codes I am not getting any error messages at all but also nothing happens; in other words the data are not transferred or entered into Excel. The following are my codes:

<Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click>
<Dim projconnect As OleDbConnection>
<Dim projCommand As New OleDbCommand>
<Dim projDataAdapter As New System.Data.OleDb.OleDbDataAdapter()>
<Dim projDataset As New System.Data.DataSet()>
<Dim projCurrencyManager As CurrencyManager>
<Dim sJobNo As String>
<Dim sYearMonth As String>
<Dim sSequence As String>
<Dim mail As New MailMessage>

<projconnect = New OleDbConnection("PROVIDER = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= P:\Admin\Finance\2010-Financial Year\pharmout_project_number_register.xls;" & _
"Extended Properties=""Excel 8.0;HDR=YES""")>

<projconnect.Open()>

<projDataAdapter.SelectCommand = New OleDbCommand>
<projDataAdapter.SelectCommand.Connection = projconnect>
<projDataAdapter.SelectCommand.CommandText = "SELECT Number FROM [ProjectNumber$] WHERE (Mid(Number, 1, 2) = Format(NOW(), 'yy')) AND (Mid(Number, 3, 2) = Format(NOW(), 'MM'))">

<projDataAdapter.SelectCommand.CommandType = CommandType.Text>

<projDataAdapter.Fill(projDataset, "ProjectNumber$")>

<projCurrencyManager = CType(Me.BindingContext(projDataset), CurrencyManager)>
<sSequence = projCurrencyManager.Count + 1>

<sYearMonth = Format(Now(), "yy") & Format(Now(), "MM")>
<sJobNo = sYearMonth & Microsoft.VisualBasic.Right("00" & sSequence, 2)>

<projCommand.Connection = projconnect>
<projCommand.CommandText = "Insert into [ProjectNumber$]" & _
"(Number) VALUES('" & sJobNo & "')">

<projCommand.CommandText = "Insert into [ProjectNumber$]" & _
"(Country, City, [Company Name], Contact, [Project Task], [Hourly Rate], [Date Submitted], Comments)" & _
"VALUES('" & txtCountry.Text & "', '" & txtCity.Text & "', '" & txtClient.Text & "', '" & _
txtManager.Text & "', '" & txtDescription.Text & "', '" & txtRate.Text & "', '" & txtStart.Text & "', '" & txtComments.Text & "')">

<If txtCountry.Text = "" Or txtCity.Text = "" Or txtClient.Text = "" Or txtManager.Text = "" Or _
txtDescription.Text = "" Or txtRate.Text = "" Or txtStart.Text = "" Or txtComments.Text = "" Then
<MessageBox.Show("One or more field is/are blank/s:" & vbCrLf & "Please fill in all fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)>
<Exit Sub>

<Me.btnOK.DialogResult = DialogResult.Retry>

<End If>

<projCommand.ExecuteNonQuery()>
<projconnect.Close()>

I would appreciate it if you could help me with this problem.

Regards
Khalil

Last edited by Khalil; June 5th, 2010 at 01:21 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
connecting to an excel spread sheet hddavie BOOK: Beginning ASP 3.0 0 June 25th, 2009 04:32 PM
connecting Excel file in VB.NET 2005 vish_vj ADO.NET 1 March 1st, 2008 10:37 AM
connecting to excel spreadsheet using asp codetoad Classic ASP Databases 1 March 21st, 2007 04:02 AM
Connecting to Excel in Access OLE Object Mack Classic ASP Databases 0 October 8th, 2004 03:43 AM
Connecting to Excel Database with ASP thehaz Classic ASP Databases 2 March 24th, 2004 05:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.