473,668 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

13 New Member
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 1436
bartonc
6,596 Recognized Expert Expert
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
6743
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 javascript or vbscript it works. I will appreciate any help. I do the following (C#):
10
2492
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 the functions and I can't find out how to do it. Here is an example of what I do and I get the following Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the...
15
4023
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 To intNumBtns - 1 pointLocate.Y += 70
9
20159
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 control. When I close the form I am expecting that the control ceases to be. However, if my object raises the event after the form has been closed, I find that there is still a user control object that handles it. Clearly the user control has not...
8
7471
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 different steps(although that may get cluttered in the design environment) 2) Create multiple WinForms (don't really know any pros or cons of this method) 3) Use a tabbed page (although I don't want to see any tabs)
1
3941
by: Gerhard | last post by:
How can I create a new contact in exchange server from a vb.net web application?
4
1537
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 this cell is 16.1. Here is my simple Page_Load code and all I want it to do is see if the decimal figure is greater than 1, if it is, then hide the YTDLabel. The error message I'm getting from VS2005 is that FormView1.FindControl("YTDLabel") is...
9
3871
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 case statement like this: sub showHelp(byval frm as String) Select Case (frm) Case "Form1" dim help as new Form1
3
4012
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 (WizardStep ws in WizardSteps) { CustomWizardStepHeader header = new CustomWizardStepHeader(); header.ID = "CustomWizardStepHeader"; ws.Controls.AddAt(0, header); }
0
8462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7405
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.