473,396 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Creating test using Wizard Control .net 2 Problem: SQL DirectCast

The problem.

I have created an exam using the control wizard. Most answers are text answers I created the SQL db. Now when I try to read the data it always gives me cast error.

I am new at this but need to figure a way to get it done. The only solution I had was the one attached but there has to be a way to use an array or create a new web ui control from a string.

When I try to do this: QLabel = {"QLabel" & (i) & ".text") and use I get an error tried using DirectCast on QLable and I get a cast error any suggestions?

One side note all tests would be text only or radiobuttonlist only not mixed like this one.

The code is below.
Expand|Select|Wrap|Line Numbers
  1.  Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
  2.  
  3.         'Get Membership GUID 
  4.         'Label2.Text = "Geeting User"
  5.         Dim instance As MembershipUser = Membership.GetUser()
  6.         Dim value As Object
  7.         If instance Is Nothing Then
  8.             Label2.Text = "NO USER IS LOGGED IN"
  9.             Exit Sub
  10.         End If
  11.         value = instance.ProviderUserKey.ToString
  12.         Dim NameId = value.ToString
  13.         'SQL Input  
  14.  
  15.         Dim QGroup
  16.         Dim QAnswer As Object
  17.         Dim QLabel
  18.  
  19.  
  20.  
  21.  
  22.         QGroup = Profile.Opportunity
  23.         Dim i As Integer
  24.         i = 0
  25.         Do Until i > 26
  26.             i = i + 1
  27.  
  28.             QAnswer = ("QAnswer" & (i) & ".Text")
  29.             QLabel = ("QLabel" & (i) & ".Text")
  30.             If i = 1 Then
  31.                 QLabel = QLabel1.Text
  32.                 QAnswer = QAnswer1.Text
  33.             ElseIf i = 2 Then
  34.                 QLabel = QLabel2.Text
  35.                 QAnswer = QAnswer2.Text
  36.             ElseIf i = 3 Then
  37.                 QLabel = QLabel3.Text
  38.                 QAnswer = QAnswer3.Text
  39.             ElseIf i = 4 Then
  40.                 QLabel = QLabel4.Text
  41.                 QAnswer = QAnswer4.Text
  42.             ElseIf i = 5 Then
  43.                 QLabel = QLabel5.Text
  44.                 QAnswer = QAnswer5.Text
  45.             ElseIf i = 6 Then
  46.                 QLabel = QLabel6.Text
  47.                 QAnswer = QAnswer6.Text
  48.             ElseIf i = 7 Then
  49.                 QLabel = QLabel7.Text
  50.                 QAnswer = QAnswer7.Text
  51.             ElseIf i = 8 Then
  52.                 QLabel = QLabel8.Text
  53.                 QAnswer = QAnswer8.Text
  54.             ElseIf i = 9 Then
  55.                 QLabel = QLabel9.Text
  56.                 QAnswer = QAnswer9.Text
  57.             ElseIf i = 10 Then
  58.                 QLabel = QLabel10.Text
  59.                 QAnswer = QAnswer10.Text
  60.             ElseIf i = 11 Then
  61.                 QLabel = QLabel11.Text
  62.                 QAnswer = QAnswer11.Text
  63.             ElseIf i = 12 Then
  64.                 QLabel = QLabel12.Text
  65.                 QAnswer = QAnswer12.Text
  66.             ElseIf i = 13 Then
  67.                 QLabel = QLabel13.Text
  68.                 QAnswer = RadioButtonList3.SelectedValue
  69.             ElseIf i = 14 Then
  70.                 QLabel = QLabel14.Text
  71.                 QAnswer = QAnswer14.Text
  72.             ElseIf i = 15 Then
  73.                 QLabel = QLabel15.Text
  74.                 QAnswer = QAnswer15.Text
  75.             ElseIf i = 16 Then
  76.                 QLabel = QLabel16.Text
  77.                 QAnswer = QAnswer16.Text
  78.             ElseIf i = 17 Then
  79.                 QLabel = QLabel17.Text
  80.                 QAnswer = QAnswer17.Text
  81.             ElseIf i = 18 Then
  82.                 QLabel = QLabel18.Text
  83.                 QAnswer = QAnswer18.Text
  84.             ElseIf i = 19 Then
  85.                 QLabel = QLabel19.Text
  86.                 QAnswer = QAnswer19.Text
  87.             ElseIf i = 20 Then
  88.                 QLabel = "Completed"
  89.                 QAnswer = "EURLA"
  90.             ElseIf i = 21 Then
  91.                 QLabel = QLabel21.Text
  92.                 QAnswer = RadioButtonList1.SelectedValue
  93.             ElseIf i = 22 Then
  94.                 QLabel = QLabel22.Text
  95.                 QAnswer = DropDownList1.SelectedValue
  96.             ElseIf i = 23 Then
  97.                 QLabel = QLabel23.Text
  98.                 QAnswer = DropDownList2.SelectedValue
  99.             ElseIf i = 24 Then
  100.                 QLabel = QLabel24.Text
  101.                 QAnswer = DropDownList3.SelectedValue
  102.             ElseIf i = 25 Then
  103.                 QLabel = QLabel25.Text
  104.                 QAnswer = DropDownList4.SelectedValue
  105.             ElseIf i = 26 Then
  106.                 QLabel = QLabel26.Text
  107.                 QAnswer = DropDownList5.SelectedValue
  108.             ElseIf i = 27 Then
  109.                 QLabel = QLabel27.Text
  110.                 QAnswer = RadioButtonList2.SelectedValue
  111.             End If
  112.  
  113.             'If QLabel.GetType().ToString() = "System.Web.UI.WebControls.Label" Then
  114.             'Dim txtLabel As Label = DirectCast(QLabel, Label)
  115.             'txtLabel.Text = Trim(txtLabel.Text)
  116.             'End If
  117.  
  118.             Dim connStr As String = ConfigurationManager.ConnectionStrings("MyProfileConnectionString").ConnectionString
  119.             Dim myConnection As New SqlConnection(connStr)
  120.             Const SQL As String = "INSERT INTO[Questions]([UserID], [QuestionGroup], [QuestLabel], [QuestAns]) Values(@UserID, @QGroup, @QLabel, @QAnswer)"
  121.  
  122.             Dim myCommand As New SqlCommand(SQL, myConnection)
  123.  
  124.             myCommand.Parameters.AddWithValue("@UserID", NameId)
  125.             myCommand.Parameters.AddWithValue("@QGroup", QGroup)
  126.             myCommand.Parameters.AddWithValue("@QLabel", QLabel)
  127.             myCommand.Parameters.AddWithValue("@QAnswer", QAnswer)
  128.  
  129.             'For Testing Only
  130.             'Label2.Text = NameId
  131.  
  132.             Try
  133.                 myConnection.Open()
  134.                 myCommand.ExecuteNonQuery()
  135.                 myConnection.Close()
  136.             Catch ex As Exception
  137.                 'For Testing Only
  138.                 Label1.Visible = True
  139.                 Label1.Text = ex.Message.ToString
  140.             End Try
  141.         Loop
May 23 '07 #1
1 1426
bartonc
6,596 Expert 4TB
Let's try the .NET Forum, shall we.
May 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
10
by: George G. | last post by:
Hi there, I am busy writing a new asp.net application and I am reusing some of my existing asp functions and methods in a user control. I need access to session, request and response in some of...
15
by: Paul Mars | last post by:
I am creating a user selectable quantity of buttons at run time and need to respond to their click events. My code: Dim btnButton as Button (global) Then in a sub: For intNumBtnsDown = 0...
9
by: Charles Law | last post by:
I have a form on which user controls are placed at runtime. When a control is added to the form a handler is added for an event that a high-level object raises, which must be handled by the new...
8
by: redeagle | last post by:
I'm wondering what the best practice is for creating a WinApp "wizard" that contains 4 or 5 "steps". Options so far are 1) Single WinForm making various controls visible/non visible at the...
1
by: Gerhard | last post by:
How can I create a new contact in exchange server from a vb.net web application?
4
by: Phillip Vong | last post by:
I'm using VS2005 and creating a simple test ASPX page in VB. I have a simple FORMVIEW1 with a label "YTDLabel" databound to a SQL DB. The DB datatype is set to decimal (18,2) and the value of...
9
by: MikeB | last post by:
Hi, I'd appreciate some help, please. I'm writing a VS2005 VB project for school and one of the requirements is that every screen should have a "Help" button. I could do it by writing a clumsy...
3
by: Allan Ebdrup | last post by:
I get the error "Error creating control: ID property is not specified" when I view my custom web control in design view. I add the control that gives an error in OnInit like this: ----- foreach...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.