We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,451 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Connection string problem using a combobox

Hello i have a problem on connecting my database.
i have this kind of code which would get the item in the combobox and use it as my connection

Dim ConFunnelLocation As String = "C:\Database\Funnel\" & Form_Funnel_Report.Combo_Funnel_EBU.Text & ".xls"

and a table

Dim TblFunnelCon As String = Form_Funnel_Report.Combo_Funnel_AM.Text & "$"

so this could be my code.

con.ConnectionString = ("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & ConFunnelLocation & "';Extended Properties=Excel 8.0;")
    con.Open()
    dt.Clear()

    ds.Tables.Add(dt)
    Try

        With Form_Funnel_Report

            Dim da As New OleDbDataAdapter("Select * from [" & TblFunnelCon & "]", con)
            da.Fill(dt)

But it cannot open my database.

unless i change my declaration to the specific name of my Table and my Excel file like this

Dim ConFunnelLocation As String =  "C:\Database\Funnel\EBU 1.xls"
Dim TblFunnelCon As String = "Sheryl Manuel$"

this work fine but i need to use combobox so it will lessen my code and it can be more flexible.

please help me. thank you in advanced.

4
Contributors
4
Replies
10 Hours
Discussion Span
3 Months Ago
Last Updated
28
Views
Zick Technology
Junior Poster
183 posts since Dec 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 3

set a break point and check the values of the strings.

tinstaafl
Nearly a Posting Virtuoso
1,336 posts since Jun 2010
Reputation Points: 360
Solved Threads: 235
Skill Endorsements: 14

Hi,

Try doing something like this:

Dim ConFunnelLocation As String

If trim(Form_Funnel_Report.Combo_Funnel_EBU.Text) <> "" then
    ConFunnelLocation = "C:\Database\Funnel\" & trim(Form_Funnel_Report.Combo_Funnel_EBU.Text) & ".xls"
else
     msgbox("Please select the excel sheet")
     exit sub
end if
G_Waddell
Practically a Master Poster
621 posts since Nov 2009
Reputation Points: 107
Solved Threads: 93
Skill Endorsements: 5

I think your problem may be just as George and tins have stated.

I think you are simply passing in a string that may have an extra space or a character that's not expected.

Step through and look at the autos to see what is happening with your code.

Begginnerdev
Practically a Posting Shark
864 posts since Apr 2010
Reputation Points: 184
Solved Threads: 142
Skill Endorsements: 8

Just occurred to me, if there's a space in the filename you may have to do this:

Dim ConFunnelLocation As String

If trim(Form_Funnel_Report.Combo_Funnel_EBU.Text) <> "" then
    ConFunnelLocation = "C:\Database\Funnel\[" & trim(Form_Funnel_Report.Combo_Funnel_EBU.Text) & "].xls"
else
     msgbox("Please select the excel sheet")
     exit sub
end if

ACTUALLY FORGET that - rush of blood to the head!!

G_Waddell
Practically a Master Poster
621 posts since Nov 2009
Reputation Points: 107
Solved Threads: 93
Skill Endorsements: 5

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0799 seconds using 2.71MB