7 Replies - 1131 Views - Last Post: 20 March 2015 - 06:05 PM

#1 Leaver441  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-March 15

Display Sql field as Label in visual studio 2010 vb.net Function

Posted 20 March 2015 - 12:19 PM

Hi,


I have around 14 pages with 6-10 questions on each which are all true and false answers, Written to the DB as 1 and 0.


I have created a summary page so it is printable which contains all 14 pages with all 6-10 questions on each then I want to display the answer by the question via a Label

I am very bad at VB.net and SQL so any help on this would be great

I managed to get the first one working, to display as "Yes or No" but the second one doesn't work (not shown in this)

Is anyone able to formulate a function so I can just call a single line of code for each label instead of having a ton of if statements?

I'm super bad at sql and vb and have hardly any experience so any help will be appreciated.

This is the code I currently have, Please edit as needed (if its even right?)

Imports System.Data
Imports System.Data.SqlClient
Public Class DraftPrint
    Inherits System.Web.UI.Page
    Dim con As New SqlConnection
    Dim comm_Id As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        comm_Id = Request.QueryString("Comm").ToString

        con.ConnectionString = "Data Source=YK15-YKC0201;Initial Catalog=Testing;Integrated Security=true"
        con.Open()

        Dim cmd As New SqlCommand
        cmd.Connection = con
        Dim str As String = "Select Indicator, Question, Answer From maca where community_ID =" + comm_Id.ToString + " order by Indicator ASC"
        Dim adapter As SqlDataAdapter = New SqlDataAdapter(str, con)
        Dim dt_summary As DataTable = New DataTable
        adapter.Fill(dt_summary)
        Dim indicator As Integer = dt_summary.Rows(0)(0)
        Dim question As Integer = dt_summary.Rows(0)(1)
        Dim answer As String = dt_summary.Rows(0)(2)

        '' Indicator 1
        If question = 1 And answer = False Then
            DraftPrint1.Text = "No"
        Else
            DraftPrint1.Text = "Yep"
        End If 



Is This A Good Question/Topic? 0
  • +

Replies To: Display Sql field as Label in visual studio 2010 vb.net Function

#2 andrewsw  Icon User is online

  • lashings of ginger beer
  • member icon

Reputation: 6337
  • View blog
  • Posts: 25,550
  • Joined: 12-December 12

Re: Display Sql field as Label in visual studio 2010 vb.net Function

Posted 20 March 2015 - 12:25 PM

This is for ASP.NET, and a WebForm, isn't it?
Was This Post Helpful? 0
  • +
  • -

#3 Leaver441  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-March 15

Re: Display Sql field as Label in visual studio 2010 vb.net Function

Posted 20 March 2015 - 12:26 PM

View Postandrewsw, on 20 March 2015 - 12:25 PM, said:

This is for ASP.NET, and a WebForm, isn't it?


yes sir
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • lashings of ginger beer
  • member icon

Reputation: 6337
  • View blog
  • Posts: 25,550
  • Joined: 12-December 12

Re: Display Sql field as Label in visual studio 2010 vb.net Function

Posted 20 March 2015 - 12:28 PM

Topic moved to ASP.NET, WebForms.
Was This Post Helpful? 0
  • +
  • -

#5 Leaver441  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-March 15

Re: Display Sql field as Label in visual studio 2010 vb.net Function

Posted 20 March 2015 - 12:29 PM

View Postandrewsw, on 20 March 2015 - 12:28 PM, said:

Topic moved to ASP.NET, WebForms.

Oops, thanks!
Was This Post Helpful? 0
  • +
  • -

#6 Leaver441  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-March 15

Re: Display Sql field as Label in visual studio 2010 vb.net Function

Posted 20 March 2015 - 12:51 PM

Can anyone help?
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • lashings of ginger beer
  • member icon

Reputation: 6337
  • View blog
  • Posts: 25,550
  • Joined: 12-December 12

Re: Display Sql field as Label in visual studio 2010 vb.net Function

Posted 20 March 2015 - 01:05 PM

You submitted this question 40 minutes ago, do not bump it after such a short time. This is a volunteer forum.
Was This Post Helpful? 0
  • +
  • -

#8 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2329
  • View blog
  • Posts: 9,356
  • Joined: 03-December 12

Re: Display Sql field as Label in visual studio 2010 vb.net Function

Posted 20 March 2015 - 06:05 PM

You would generally do the calling in a loop and call the function to return what you need. But, based from the code you posted I don't think that you designed it in a modular fashion to allow for it.


Pseudo code:

public function CheckAnswer( byVal answer as string, byVal questionId as int32) as string
   
    'lookup question and see if the answer is correct
    'Code omitted
    if correct 
        return "Correct" 
    else
        return "Not Correct"

End function


You code go further and create another function thats job is to findout what the answer was and return it. Making the system even more modular for other pieces to use. and the above could call that function to see the answer.

This post has been edited by astonecipher: 20 March 2015 - 06:07 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1