displaying data from a dataset in a datagrid

M

Machelle

Good Morning All,

I'm a new developer trying to use a datagrid to display
the results of a query referenced in my stored
procedure. I'm using ADO.NET & SQL Server 2000.

I have several questions:

1. Is the below code to fill the data set and bind the
datasource to the data grid supposed to be in the Page
Load event code or in the Web Form Designer Generated
Code?

'Fill the dataset
DsFinTrngDB1.Tables.Add(New DataTable
("dtAllCurriculum"))
DsFinTrngDB1.Tables(0).BeginLoadData()
daFinTrngDB.Fill(DsFinTrngDB1, "dtAllCurriculum")
DsFinTrngDB1.Tables(0).EndLoadData()
dgFinTrngDB.DataSource = DsFinTrngDB1.Tables
(0).DefaultView

2. If I build & browse the page in Visual Studio, should
I be able to see the data in the grid in the browser, or
is it just visible when running on the real web server? I
just have IIS loaded on my pc.

3. What am I missing in my code below? Why don't I see
data in my grid when I view the page in the browser?





My Full code:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page

Protected WithEvents SqlSelectCommand1 As
System.Data.SqlClient.SqlCommand
Protected WithEvents DsFinTrngDB1 As
FDO_Dynamic_Webpages.dsFinTrngDB
Protected WithEvents daFinTrngDB As
System.Data.SqlClient.SqlDataAdapter
Protected WithEvents conFinTrngDB As
System.Data.SqlClient.SqlConnection
Protected WithEvents dgFinTrngDB As
System.Web.UI.WebControls.DataGrid
Protected WithEvents Button1 As
System.Web.UI.WebControls.Button
Protected WithEvents Label1 As
System.Web.UI.WebControls.Label


#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.daFinTrngDB = New
System.Data.SqlClient.SqlDataAdapter()
Me.SqlSelectCommand1 = New
System.Data.SqlClient.SqlCommand()
Me.conFinTrngDB = New
System.Data.SqlClient.SqlConnection()
Me.DsFinTrngDB1 = New
FDO_Dynamic_Webpages.dsFinTrngDB()
CType(Me.DsFinTrngDB1,
System.ComponentModel.ISupportInitialize).BeginInit()
'
'daFinTrngDB
'
Me.daFinTrngDB.SelectCommand =
Me.SqlSelectCommand1
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText
= "prc_all_competency_curriculum"
Me.SqlSelectCommand1.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlSelectCommand1.Connection = Me.conFinTrngDB
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4,
System.Data.ParameterDirection.ReturnValue, False, CType
(10, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, 0))
'
'conFinTrngDB
'
Me.conFinTrngDB.ConnectionString = "data
source=OREA2SQL017; initial catalog=Fin_Trng_DB;
workstation id=MACHANDL-MOB" & _
"L;persist security info=False; packet size=4096;
Trusted_Connection=Yes"
'
'DsFinTrngDB1
'
Me.DsFinTrngDB1.DataSetName = "dsFinTrngDB"
Me.DsFinTrngDB1.Locale = New
System.Globalization.CultureInfo("en-US")
Me.DsFinTrngDB1.Namespace
= "http://www.tempuri.org/dsFinTrngDB.xsd"
CType(Me.DsFinTrngDB1,
System.ComponentModel.ISupportInitialize).EndInit()

End Sub

Private Sub Page_Init(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web
Form Designer
'Do not modify it using the code editor.
InitializeComponent()


End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'Fill the dataset
DsFinTrngDB1.Tables.Add(New DataTable
("dtAllCurriculum"))
DsFinTrngDB1.Tables(0).BeginLoadData()
daFinTrngDB.Fill(DsFinTrngDB1, "dtAllCurriculum")
DsFinTrngDB1.Tables(0).EndLoadData()
dgFinTrngDB.DataSource = DsFinTrngDB1.Tables
(0).DefaultView
'dgFinTrngDB.DataBind()


End Sub
 
R

Ravikanth[MVP]

Hi

are you sure whether data exists in database. If data
exist in database you should be able to view in webpage.

Ravikanth[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top