473,405 Members | 2,185 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,405 software developers and data experts.

How To Get the data from SQL database to display in GridView

Hi Guys Can you help me please in my project, I have tblItemList in my SQL DB. I want to display all the data in my tblItemList in GridView control....
How Can I Do That in VB Script using VB.Net...

Thank you...

Please Help Me...

Regards,
Jared
Feb 22 '08 #1
6 12939
jeffstl
432 Expert 256MB
Check this thread out.

http://www.thescripts.com/forum/thread773585.html
Feb 22 '08 #2
Hi Guys Can you help me please in my project, I have tblItemList in my SQL DB. I want to display all the data in my tblItemList in GridView control....
How Can I Do That in VB Script using VB.Net...

Thank you...

Please Help Me...
Feb 23 '08 #3
Hi jeffstl,

Thanks for your reply, I appreciate it, but I got an error when I write the code below.... The Error Message: Type 'System.data.sqlclient.reader' has no constructors
What should I do? can help me please to debug my code...I'm using MSSQL 2005 as my database and I used ASP.Net in developing the system and VB script.
thank you....

Expand|Select|Wrap|Line Numbers
  1. ---------Name Space----------
  2. <%@ Import Namespace="System.Data" %>
  3. <%@ Import Namespace="System.Data.SqlClient" %>
  4. <%@ Import Namespace="system.data.sqlclient.sqldatareader" %>
  5.  
  6. --------VB Script-------------------
  7. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  8.  
  9.         Dim con As New SqlConnection
  10.  
  11.         con.ConnectionString = "Integrated Security=True;data source=ph-erwinm1;" & "persist security info=false;Initial Catalog=ITP"
  12.         Dim strSql As String
  13.         Dim SQLComm As New SqlCommand
  14.         Dim dbread As New SqlDataReader
  15.  
  16.  
  17.         strSql = "SELECT intITPCodeFK,intQuantity FROM tblItemlist"
  18.         SQLComm = New SqlCommand(strSql, con)
  19.         dbread = SQLComm.ExecuteReader()
  20.         GridITPSumm.DataSource = dbread
  21.         GridITPSumm.DataBind()
  22.  
  23.         dbread.Close()
  24.         con.Close()    
  25.  
  26.     End Sub
  27.  
  28.  
  29.  
  30. ------------------HTML-----------------------
  31.     <asp:DataGrid id="GridITPSumm" runat="server"
  32.     AutoGenerateColumns="False" CellPadding="3"
  33.     HeaderStyle-BackColor="#A4A6CF"
  34.     HeaderStyle-ForeColor="000033"
  35.     HeaderStyle-HorizontalAlign="Left"
  36.     HeaderStyle-Font-Bold="True"
  37.     BackColor="#eeeeee" Width="50%"
  38.     HorizontalAlign="Left"
  39.     Font-Bold="True" 
  40.     Font-Names="Tahoma"
  41.     Font-Size="10pt">
  42.  
  43.     <AlternatingItemStyle BackColor="White" />
  44.  
  45.     <Columns>
  46.         <asp:BoundColumn HeaderText="ITP COde" DataField="intITPCodeFK" />
  47.         <asp:BoundColumn HeaderText="QTY" DataField="intQuantity" />                       
  48.     </Columns>        
  49. </asp:DataGrid>
Feb 23 '08 #4
jeffstl
432 Expert 256MB
I dont know that much about namespace, or if thats actually the problem but I did notice a few things.

You need the <script> tags around your code-behind, and you also need to open your database connection

see below changes

Expand|Select|Wrap|Line Numbers
  1.  
  2. ---------Name Space----------
  3. <%@ Import Namespace="System.Data" %>
  4. <%@ Import Namespace="System.Data.SqlClient" %>
  5. <%@ Import Namespace="system.data.sqlclient.sqldatareader" %>
  6.  
  7. --------VB Script-------------------
  8.  
  9. 'ADD SCRIPT TAG
  10. <script  runat="server">
  11.  
  12. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  13.  
  14.         Dim con As New SqlConnection
  15.  
  16.         con.ConnectionString = "Integrated Security=True;data source=ph-erwinm1;" & "persist security info=false;Initial Catalog=ITP"
  17.         Dim strSql As String
  18.         Dim SQLComm As New SqlCommand
  19.         Dim dbread As New SqlDataReader
  20.  
  21.          'OPEN DB CONNECTION   
  22.         con.Open      
  23.  
  24.        strSql = "SELECT intITPCodeFK,intQuantity FROM tblItemlist"
  25.         SQLComm = New SqlCommand(strSql, con)
  26.         dbread = SQLComm.ExecuteReader()
  27.         GridITPSumm.DataSource = dbread
  28.         GridITPSumm.DataBind()
  29.  
  30.         dbread.Close()
  31.         con.Close()    
  32.  
  33.     End Sub
  34.  
  35.  'CLOSE SCRIPT TAG
  36. </Script> 
  37. ------------------HTML-----------------------
  38.     <asp:DataGrid id="GridITPSumm" runat="server"
  39.     AutoGenerateColumns="False" CellPadding="3"
  40.     HeaderStyle-BackColor="#A4A6CF"
  41.     HeaderStyle-ForeColor="000033"
  42.     HeaderStyle-HorizontalAlign="Left"
  43.     HeaderStyle-Font-Bold="True"
  44.     BackColor="#eeeeee" Width="50%"
  45.     HorizontalAlign="Left"
  46.     Font-Bold="True" 
  47.     Font-Names="Tahoma"
  48.     Font-Size="10pt">
  49.  
  50.     <AlternatingItemStyle BackColor="White" />
  51.  
  52.     <Columns>
  53.         <asp:BoundColumn HeaderText="ITP COde" DataField="intITPCodeFK" />
  54.         <asp:BoundColumn HeaderText="QTY" DataField="intQuantity" />                       
  55.     </Columns>        
  56. </asp:DataGrid>
  57.  
  58.  
Feb 23 '08 #5
hi guys,
can you help me please....

I'm using asp.net,mssql server2005 and vb script....

i dont know how to display data from db to gridview....
i want to use datatable in displaying data, so that i can edit,select and can allow paging to my gridview control.

Thank You in advance I appreciate your support...
Feb 24 '08 #6
I dont know that much about namespace, or if thats actually the problem but I did notice a few things.

You need the <script> tags around your code-behind, and you also need to open your database connection

see below changes

Expand|Select|Wrap|Line Numbers
  1.  
  2. ---------Name Space----------
  3. <%@ Import Namespace="System.Data" %>
  4. <%@ Import Namespace="System.Data.SqlClient" %>
  5. <%@ Import Namespace="system.data.sqlclient.sqldatareader" %>
  6.  
  7. --------VB Script-------------------
  8.  
  9. 'ADD SCRIPT TAG
  10. <script  runat="server">
  11.  
  12. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  13.  
  14.         Dim con As New SqlConnection
  15.  
  16.         con.ConnectionString = "Integrated Security=True;data source=ph-erwinm1;" & "persist security info=false;Initial Catalog=ITP"
  17.         Dim strSql As String
  18.         Dim SQLComm As New SqlCommand
  19.         Dim dbread As New SqlDataReader
  20.  
  21.          'OPEN DB CONNECTION   
  22.         con.Open      
  23.  
  24.        strSql = "SELECT intITPCodeFK,intQuantity FROM tblItemlist"
  25.         SQLComm = New SqlCommand(strSql, con)
  26.         dbread = SQLComm.ExecuteReader()
  27.         GridITPSumm.DataSource = dbread
  28.         GridITPSumm.DataBind()
  29.  
  30.         dbread.Close()
  31.         con.Close()    
  32.  
  33.     End Sub
  34.  
  35.  'CLOSE SCRIPT TAG
  36. </Script> 
  37. ------------------HTML-----------------------
  38.     <asp:DataGrid id="GridITPSumm" runat="server"
  39.     AutoGenerateColumns="False" CellPadding="3"
  40.     HeaderStyle-BackColor="#A4A6CF"
  41.     HeaderStyle-ForeColor="000033"
  42.     HeaderStyle-HorizontalAlign="Left"
  43.     HeaderStyle-Font-Bold="True"
  44.     BackColor="#eeeeee" Width="50%"
  45.     HorizontalAlign="Left"
  46.     Font-Bold="True" 
  47.     Font-Names="Tahoma"
  48.     Font-Size="10pt">
  49.  
  50.     <AlternatingItemStyle BackColor="White" />
  51.  
  52.     <Columns>
  53.         <asp:BoundColumn HeaderText="ITP COde" DataField="intITPCodeFK" />
  54.         <asp:BoundColumn HeaderText="QTY" DataField="intQuantity" />                       
  55.     </Columns>        
  56. </asp:DataGrid>
  57.  
  58.  


Hey jeffstl thank you...
but i have a problem in binding data in gridview because of using SqlDataReader, I can't allow paging in my gridview because it is readonly, how can i allow paging in my gridview?
thank you...
please help
Feb 25 '08 #7

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

Similar topics

4
by: washoetech | last post by:
Hello, I am working on a project where I need to be able to grab the data from an Excel spreadsheet and create a new table in my database based on the columns in the spreadsheet. After the...
2
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
1
by: Siva | last post by:
Hi, I have a 3 tier ASP.Net app for a handheld which needs to fetch orders from database via a DAL and populate it in a gridview using objectdatasource. In the search page I have a few parameters...
5
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
8
by: Greg Lyles | last post by:
Hi all, I'm trying to develop an ASP.NET 2.0 website and am running into some real problems with what I thought would be a relatively simple thing to do. In a nutshell, I'm stuck on trying to...
3
by: Mike | last post by:
I'm using the 2.0 framework and cannot get a gridview to return records with an objectDataSource. I can preview the data from the datatable. To make this as simple as possible I used the wizard...
0
by: Adam Sandler | last post by:
Hello, Prior to posting I looked at http://groups.google.com/group/ microsoft.public.dotnet.framework.aspnet/browse_thread/thread/ d8d5ae243614085e/d4fd6c4a5aa56f75 ...
2
by: chike_oji | last post by:
Please can someone help me. I am writing a web application, that allows for the upload of an excel sheet into the database. I have an upload button and a save button. The upload button allows...
1
by: Dave | last post by:
I'm having problems getting the GridView to reliably display a large amount of data (50,000+ rows). I am working my way through the excellent book “Real World ASP.NET Best Practices” by Farhan...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.