How can I map datagrid with database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sacha4
    New Member
    • Sep 2007
    • 11

    How can I map datagrid with database?

    Hi ,

    I am trying to map datagrid to database. There is one field that is numeric in the database, but I want to show in the datagrid that is on the web page as a string. For an example, if the database says 1, the datagrid will show "Qualified"
    if 2, "Disqualifi ed." So on and so forth. I am not sure how to do this. The programming is done in VB.Net. And since the .Net version is 1.1 so i am not able to use gridview. I have tried dataformatting but to no avail.

    Please please need help!

    Thanks in advance!
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Can you just change your SELECT statement to reflect that?
    [code=SQL]
    SELECT
    CASE
    WHEN SomeIntColumn = 1 THEN
    'Qualified'
    WHEN SomeIntColumn = 2 THEN
    'Unqualified'
    ELSE
    'SomethingElse'
    END AS [QualificationCo lumnName]
    FROM SomeTable
    [/code]

    Comment

    • sacha4
      New Member
      • Sep 2007
      • 11

      #3
      Code:
      Private Sub Datagrid()
      
      
      
              '  Dim myDataTable As New DataTable("MyData")
      
              Dim connectionString As String =""
              Dim dbcon As System.Data.IDbConnection
              dbcon = New SqlConnection(connectionString)
              dbcon.Open()
              Dim dbcmd As System.Data.IDbCommand = dbcon.CreateCommand()
              Dim sql As String = "SELECT * FROM images where product = '" & ddProducts.SelectedItem.Text & "'"
      
      
              dbcmd.CommandText = sql
      
            
      
      
              Dim datareader As System.Data.IDataReader = dbcmd.ExecuteReader()
              Dim stats = 1
              If (datareader.Read()) Then
                  If (Not datareader.IsDBNull(0)) Then
      
      
      
                      For stats = 1 To 5
      
                          Dim str As String = Decimal.Parse(stats)
      
      
      
                          Select Case str
                              Case "1"
                                  str = "Qualified"
                              Case "2"
                                  str = "Disqualified"
                           
                          End Select
                      Next stats
      
                  End If
              End If
              DgProductActions.DataSource = datareader
              DgProductActions.DataBind()
      
      
              datareader.Close()
              datareader = Nothing
              dbcmd.Dispose()
              dbcmd = Nothing
              dbcon.Close()
              dbcon = Nothing
      
      
          End Sub

      This is the backend and the front end code is
      Code:
      <asp:datagrid id="DgProductActions" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 352px"
      				runat="server" Width="520px" BorderStyle="Solid" BorderColor="Black" PageSize="15" AutoGenerateColumns="False"
      				CellSpacing="2" Visible="true" Font-Size="12px" Font-Names="Verdana" Height="112px">
      				<AlternatingItemStyle BackColor="#99DDDD"></AlternatingItemStyle>
      				<HeaderStyle Font-Size="X-Small" Font-Bold="false" HorizontalAlign="Left" VerticalAlign="Middle"></HeaderStyle>
      				<Columns>
      					<asp:BoundColumn DataField="Product" HeaderText="Product" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
      					<asp:BoundColumn DataField="Candidate" HeaderText="Candidate" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
      					<asp:BoundColumn DataField="Printer" HeaderText="Printer" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
      					<asp:BoundColumn DataField="OEM" HeaderText="OEM" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
      					<asp:BoundColumn DataField="Status" HeaderText="Status" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
      					<asp:BoundColumn DataField="mac_location" HeaderText="Mac_Location" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
      				</Columns>
      			</asp:datagrid>
      Any help is really appreciated... Select statement doesnt work in this case!
      Last edited by Curtis Rutland; Oct 28 '08, 05:43 PM. Reason: added [CODE] tags

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        Please enclose your posted code in [code] tags (See How to Ask a Question).

        This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

        Please use [code] tags in future.

        MODERATOR

        Comment

        Working...