[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.1

VB.NET Combobox gets values from SQL Database

Asked by anon1m0us in SQL Query Syntax, SQL Server 2005, Microsoft Visual Basic.Net

Tags: VB.NET, SQL

Hi,
I have a form with a browse feature and a combobox.
I need users to first select the file they want to import. Second, select a group that is defined in the SQL DB.
Both of these MUST be selected before continuing to display a chart.

Based on the combobox selection, will determine which group will be displayed in my Excel sheet. In my example I used segment="IT", but there are numerious groups defined in the DB.

i tried numerious code, but could not get it to work.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
Imports System.Windows.Forms.ComboBox
Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop
Imports System.Drawing
Imports System.IO
Imports System.Data.Common
Imports System.Data.OleDb
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Resources
Imports System.Drawing.Drawing2D
Imports System.Drawing.Printing
Imports System.Data.SqlClient
 
 
Public Class frmClApps1
    Dim oExcel As Excel.Application
 
 
 
 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBrowse.Click
        Dim cn As ADODB.Connection
        Dim rst As ADODB.Recordset
        Dim strSQL As String
        Dim lngRecsAff As Long
        Dim rsPubs As ADODB.Recordset
        Dim objSaveFileDialog As New SaveFileDialog
 
 
        'Opening SQL Database connection
        cn = New ADODB.Connection
        cn.Open("Provider=SQLOLEDB;Data Source=Test;" & _
            "Initial Catalog=Apps;User ID=Admin;Password=")
 
 
        Using oExcel As New OpenFileDialog
            oExcel.Title = "Open File Dialog"
            oExcel.InitialDirectory = "c:\"
            oExcel.Filter = "Excel files (*.xls)|*.xls*"
            oExcel.FilterIndex = 2
            oExcel.RestoreDirectory = True
 
            If oExcel.ShowDialog() = Windows.Forms.DialogResult.OK Then
                strSQL = "SELECT * INTO Data FROM " & _
                "OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0', " & _
                "'Data Source=" & _
                 oExcel.FileName & _
                 ";" & _
                "Extended Properties=Excel 8.0')...[Data$]WHERE Department LIKE '%Support%'"
                ' Debug.Print(strSQL)
 
                With cn
                    'Drops the existing Table
                    .Execute("DROP TABLE Data")
                    .Execute(strSQL, lngRecsAff, ADODB.ExecuteOptionEnum.adExecuteNoRecords)
                    .Execute("ALTER TABLE Data ADD JobFunction varchar(50),Segment varchar(5)")
                    .Execute("dbo.sp_UpdateSegment")
                    .Execute("dbo.sp_UpdateData")
                End With
            End If
        End Using
 
 
 
 
        ' Create a recordset object.
        rsPubs = New ADODB.Recordset
        With rsPubs
            ' Assign the Connection object.
            .ActiveConnection = cn
            'Extract the required records.
            .Open("SELECT [Project Name],MIN([TASK Name]),JOBFunction" & _
                " from Data" & _
               " Where segment ='IT' " & _
               " GROUP BY [Project name],[TASK Name],JobFunction" & _
               " ORDER BY JOBFunction")
 
            ' Copy the records into cell A1 on Sheet1.
            ' Create the Excel application.
            oExcel = CreateObject("Excel.Application")
            oExcel.Visible = False
            oExcel.Workbooks.Add()
 
            With oExcel.Worksheets("Sheet1")
                .Range("A2").CopyFromRecordset(rsPubs)
                .Range("A1") = "Project Name"
                .Range("B1") = "Task Name"
                .Range("C1") = "Mapped To"
                .Range("A1:C1").Font.Bold = True
                .Columns("A:Z").AutoFit()
            End With
 
            'Tidy(up)
            .Close()
        End With
 
        With rsPubs
 
            ' Extract the required records.
            .Open("SELECT JOBFunction, SUM(HOURS)as [Total Hours] from Data" & _
           " WHERE Segment ='IB' " & _
           " GROUP BY JobFUnction")
            With oExcel.Worksheets("Sheet2")
                .Range("A2").CopyFromRecordset(rsPubs)
                .Range("A1") = "Job Funtion"
                .Range("B1") = "Total Hours"
                .Range("A1:B1").Font.Bold = True
                .Columns("A:Z").AutoFit()
            End With
 
            ' Tidy up
            .Close()
        End With
 
        cn.Close()
        cn = Nothing
        PieChart()
 
        oExcel.Visible = True
 
 
    End Sub
 
    Sub PieChart()
 
 
        With (oExcel.Worksheets("sheet2").ChartObjects.Add(Left:=100, Width:=375, Top:=150, Height:=225))
            .Chart.SetSourceData(Source:=oExcel.Worksheets("Sheet2").Range("A2:B6"))
            .Chart.ChartType = Excel.XlChartType.xl3DPieExploded
            .Chart.ApplyLayout(1)
 
        End With
 
        With oExcel.Worksheets("sheet2").ChartObjects(1).Chart
            .HasTitle = True
            .ChartTitle.Text = "Apps"
        End With
        oExcel.Worksheets("sheet2").Name = "dash by team"
        oExcel.Worksheets("sheet1").Name = "Summary by Group"
 
    End Sub
 
 
 
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Verify the cancel
        Dim result As DialogResult = MessageBox.Show("Are you sure you want to quit?", "Confirm Operation", MessageBoxButtons.YesNo)
        If result = DialogResult.Yes Then
            Me.Close()
        End If
 
    End Sub
[+][-]08/25/09 08:34 AM, ID: 25178667Accepted Solution

View this solution now by starting your 30-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: SQL Query Syntax, SQL Server 2005, Microsoft Visual Basic.Net
Tags: VB.NET, SQL
Sign Up Now!
Solution Provided By: CodeCruiser
Participating Experts: 1
Solution Grade: B
 
[+][-]08/25/09 01:11 AM, ID: 25175359Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]08/25/09 05:23 AM, ID: 25176703Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/25/09 06:01 AM, ID: 25177046Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]08/25/09 07:15 AM, ID: 25177810Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/25/09 07:19 AM, ID: 25177850Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]08/25/09 08:07 AM, ID: 25178366Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/25/09 08:13 AM, ID: 25178434Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/25/09 08:15 AM, ID: 25178461Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]08/25/09 08:28 AM, ID: 25178605Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/25/09 08:29 AM, ID: 25178616Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/25/09 08:33 AM, ID: 25178662Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]08/25/09 08:39 AM, ID: 25178725Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/25/09 08:39 AM, ID: 25178737Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]08/25/09 08:43 AM, ID: 25178780Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/26/09 02:48 AM, ID: 25185757Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]08/26/09 05:33 AM, ID: 25186829Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/26/09 05:36 AM, ID: 25186849Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]08/26/09 05:38 AM, ID: 25186866Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/26/09 06:01 AM, ID: 25187056Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]08/26/09 06:03 AM, ID: 25187081Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]08/26/09 07:07 AM, ID: 25187812Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/26/09 07:11 AM, ID: 25187856Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]08/26/09 07:16 AM, ID: 25187906Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/26/09 07:24 AM, ID: 25187982Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625