How to Display multiple columns in a label

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vkas
    New Member
    • Feb 2009
    • 78

    How to Display multiple columns in a label

    Hi to all !

    MY Case:


    i have created a label
    i had a table(Empinfo) for Employee information in SQL server 2000
    my Query ="Select Firstname,lastn ame from Empinfo"
    my connection ok!
    i get connected and display the values of both the columns in the datagridveiw its ok too and done

    My Problem
    But i want to display the both the column in that label..
  • alamodgal
    New Member
    • Dec 2008
    • 38

    #2
    hiiiiiiii
    Can pls explain what u actually want.You want to display values of two fields of your table in one column of your grid.Is it this that u want?

    Comment

    • Vkas
      New Member
      • Feb 2009
      • 78

      #3
      i want
      want to display values of two fields of your table in one Label in my page .

      i had done it but i want to give space that is being not done any idea

      mean
      I had a table (empinfo)
      had three columns

      firstName | Middle Name|Last name|emp id
      sara |Ahmed | Gilani | 1
      wahaj |ali | khan |2



      this type of table
      now i had a label control and i want to display (firstname Lastname ) in that label (sara Gilani)

      i hope you understand

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        You retrieve the data from the database. When you do this it's stored in some Object. Use that Object to set the Text property of the Label.

        For me to better explain what I'm getting at here please post the code you are using to retrieve the data from the database.

        Comment

        • alamodgal
          New Member
          • Dec 2008
          • 38

          #5
          hiiiiiiiiiiiiii
          You just make ur query like this and fetch name in label like this:



          query=select firstname+' '+lastname as name from empinfo


          You can give as much space as you want in single quotes.

          Comment

          • Vkas
            New Member
            • Feb 2009
            • 78

            #6
            hi Alam!

            i have tried your method but it gives me exception
            "Index was out of the bound of array"

            Comment

            • Vkas
              New Member
              • Feb 2009
              • 78

              #7
              hi farnival i am sending you the code
              let me tell you one thing that i had created a class named Database with some function!!!!

              My Class Data base code!!
              Code:
              Imports System.Data.SqlClient
              Imports Microsoft.VisualBasic
              
              
              Public Class Database
                  Private Shared mycommand As SqlCommand
                  Private Shared dr As SqlDataReader
                  Private Shared da As SqlDataAdapter
                  Private Shared con As SqlConnection
                  Shared Function connection()
                      Dim con As SqlConnection = New SqlConnection
                      con.ConnectionString = "data source = (local) ; initial catalog = WisHRM ; Integrated Security = SSPI"
                      Return con
                  End Function
                  Shared Sub GetSelectQuery(ByVal query As String)
                      con = Database.connection
                      con.Open()
                      mycommand = New SqlCommand(query, con)
                      dr = mycommand.ExecuteReader
                      dr.Read()
                  End Sub
                  Shared Function GetResult()
                      Return dr
                  End Function
                  Shared Sub GetDsQuery(ByVal query As String)
                      con = Database.connection
                      con.Open()
                      da = New SqlDataAdapter(query, con)
                  End Sub
                  Shared Function GetDsResult()
                      Return da
                  End Function
                  Shared Function GetUpdateQuery(ByVal query As String)
                      con = Database.connection
                      con.Open()
                      Dim i As Integer = 0
                      mycommand = New SqlCommand(query, con)
                      i = mycommand.ExecuteNonQuery
                      Return i
                  End Function
              
              End Class

              Now i am calling the function of that class to connect and get result from database!
              my Welcome Page

              i had a label in it !!

              its code
              Code:
              Database.GetSelectQuery("Select strFirstName,strLastName from tblEmployee where intEmployeeid = 4)
                              lblName.Text = Database.GetResult(0) + Database.GetResult(1)
              as i told you i had acheived to show firstname and last name through the code
              but the problem now remaining in that is that i cant give space i had tried the Alamodgal method but it gives the same Error !! as i had written!!
              Last edited by Frinavale; Feb 25 '09, 03:50 PM. Reason: Added [code] tags: Please post code between [code][/code] tags

              Comment

              • alamodgal
                New Member
                • Dec 2008
                • 38

                #8
                Use this code

                Database.GetSel ectQuery("Selec t strFirstName+' '+strLastName as name from tblEmployee where intEmployeeid = 4)
                lblName.Text = Database.GetRes ult(0)

                Comment

                • Vkas
                  New Member
                  • Feb 2009
                  • 78

                  #9
                  thankkkss thankkssss
                  Alam!
                  wawooo!!
                  this is the first 100% solved problem of mine from internet in which it worked 100% right

                  i am very great full to u !

                  you are here new but seems to have very much more experience

                  Comment

                  • alamodgal
                    New Member
                    • Dec 2008
                    • 38

                    #10
                    hiiiiiiiiiiii
                    Its ok.
                    Ya im new here but not much experienced.

                    Comment

                    • Vkas
                      New Member
                      • Feb 2009
                      • 78

                      #11
                      yapp hahahah
                      but more experience than me

                      Comment

                      • Vkas
                        New Member
                        • Feb 2009
                        • 78

                        #12
                        do u have any idea of web user control

                        Comment

                        • alamodgal
                          New Member
                          • Dec 2008
                          • 38

                          #13
                          ya whats ur problem in that

                          Comment

                          Working...