473,396 Members | 2,011 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.

How can I map datagrid with database?

11
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, "Disqualified." 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!
Oct 15 '08 #1
3 1113
Plater
7,872 Expert 4TB
Can you just change your SELECT statement to reflect that?
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. CASE 
  3. WHEN SomeIntColumn = 1 THEN
  4.    'Qualified'       
  5. WHEN SomeIntColumn = 2 THEN
  6.    'Unqualified' 
  7. ELSE
  8.    'SomethingElse'
  9. END AS [QualificationColumnName]
  10. FROM SomeTable
  11.  
Oct 15 '08 #2
sacha4
11
Expand|Select|Wrap|Line Numbers
  1. Private Sub Datagrid()
  2.  
  3.  
  4.  
  5.         '  Dim myDataTable As New DataTable("MyData")
  6.  
  7.         Dim connectionString As String =""
  8.         Dim dbcon As System.Data.IDbConnection
  9.         dbcon = New SqlConnection(connectionString)
  10.         dbcon.Open()
  11.         Dim dbcmd As System.Data.IDbCommand = dbcon.CreateCommand()
  12.         Dim sql As String = "SELECT * FROM images where product = '" & ddProducts.SelectedItem.Text & "'"
  13.  
  14.  
  15.         dbcmd.CommandText = sql
  16.  
  17.  
  18.  
  19.  
  20.         Dim datareader As System.Data.IDataReader = dbcmd.ExecuteReader()
  21.         Dim stats = 1
  22.         If (datareader.Read()) Then
  23.             If (Not datareader.IsDBNull(0)) Then
  24.  
  25.  
  26.  
  27.                 For stats = 1 To 5
  28.  
  29.                     Dim str As String = Decimal.Parse(stats)
  30.  
  31.  
  32.  
  33.                     Select Case str
  34.                         Case "1"
  35.                             str = "Qualified"
  36.                         Case "2"
  37.                             str = "Disqualified"
  38.  
  39.                     End Select
  40.                 Next stats
  41.  
  42.             End If
  43.         End If
  44.         DgProductActions.DataSource = datareader
  45.         DgProductActions.DataBind()
  46.  
  47.  
  48.         datareader.Close()
  49.         datareader = Nothing
  50.         dbcmd.Dispose()
  51.         dbcmd = Nothing
  52.         dbcon.Close()
  53.         dbcon = Nothing
  54.  
  55.  
  56.     End Sub

This is the backend and the front end code is
Expand|Select|Wrap|Line Numbers
  1. <asp:datagrid id="DgProductActions" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 352px"
  2.                 runat="server" Width="520px" BorderStyle="Solid" BorderColor="Black" PageSize="15" AutoGenerateColumns="False"
  3.                 CellSpacing="2" Visible="true" Font-Size="12px" Font-Names="Verdana" Height="112px">
  4.                 <AlternatingItemStyle BackColor="#99DDDD"></AlternatingItemStyle>
  5.                 <HeaderStyle Font-Size="X-Small" Font-Bold="false" HorizontalAlign="Left" VerticalAlign="Middle"></HeaderStyle>
  6.                 <Columns>
  7.                     <asp:BoundColumn DataField="Product" HeaderText="Product" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
  8.                     <asp:BoundColumn DataField="Candidate" HeaderText="Candidate" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
  9.                     <asp:BoundColumn DataField="Printer" HeaderText="Printer" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
  10.                     <asp:BoundColumn DataField="OEM" HeaderText="OEM" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
  11.                     <asp:BoundColumn DataField="Status" HeaderText="Status" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
  12.                     <asp:BoundColumn DataField="mac_location" HeaderText="Mac_Location" HeaderStyle-Font-Bold="True"></asp:BoundColumn>
  13.                 </Columns>
  14.             </asp:datagrid>
Any help is really appreciated... Select statement doesnt work in this case!
Oct 28 '08 #3
Curtis Rutland
3,256 Expert 2GB
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
Oct 28 '08 #4

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

Similar topics

3
by: EMW | last post by:
How can I put everything that is in a datagrid into a SQL server database (which should be readable by an PocketPC program)? There is probably a simple solution for it, but as always it is...
0
by: Gamze | last post by:
Hi, How can i get values from datagrid to combobox and should select the same name as in datagrid row on the combobox control In my vb.net windows application ,i have combobox which is...
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
4
by: Rod | last post by:
I posted a message to this group yesterday asking how to pass parameters to a web form that is the source of an IFrame on a parent web form. I've gotten my answer, and it works. Thanks! Now I...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value....
4
by: cooltech77 | last post by:
Hi, I am trying to build the following functionality in the datagrid. I have a lot of columns in the datagrid which are being populated from the database and the user needs to scroll...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.