C
CDnIDmatt
Guest
I have built a data base in SQLServer 2008r2 that stores all the information pertaining to managing a montly budget, including stored procedures and views for updating and viewing the data.
I am trying to build a Web front end that will eventally be capaible of displaying each months set of data and allow for updating.
At this stage I am just trying to display data into different gridviews (gridview1 and gridview2) which will show all the bills in pay period 1 and pay period 2.
I have a stored procedure that will accept variables @month and @payper to select the month id and pay period id.
I can get the data to display but I dont want to create the same code over and over again; This is where I am stuck, creating a method or class to call the data to grid view with the different variables.
I seem to be close by the GridView1.DataSource = ds doesnt work when I try to do this as a class.
The aspx page
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Budget.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<html xmlns="http://www.w3.org/1999/xhtml
<head runat="server
<title></title>
</head>
<body>
<form id="form1" runat="server
<asp:GridView ID="GridView1" runat="server
</asp:GridView>
<asp:GridView ID="GridView2" runat="server
</asp:GridView>
</form>
</body>
</html>
Aspx.vb file
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con = GetConnect()
con.Open()
Dim str As String = "p_DisplayBills 1, 1"
Dim cmd As New SqlCommand(str, con)
Dim da As New SqlDataAdapter(cmd)
Dim Ds As New DataSet()
da.Fill(Ds, "p_DisplayBills")
GridView1.DataSource = Ds
GridView1.DataBind()
Dim str2 As String = "p_DisplayBills 1, 2"
Dim cmd2 As New SqlCommand(str2, con)
Dim da2 As New SqlDataAdapter(cmd2)
Dim ds2 As New DataSet()
da2.Fill(ds2, "p_DisplayBills")
GridView2.DataSource = ds2
GridView2.DataBind()
Dim GridView1DataDisplay As New DataDisplay
GridView1DataDisplay.Display = "p_DisplayBills"
GridView1DataDisplay.DisplayD = "p_DisplayBills 1, 2"
GridView1.DataSource = Ds
GridView1.DataBind()
con.Close()
End Sub
End Class
The Class file
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class DataDisplay
Public Property DisplayD As String
Public Property Display As String
Public Sub DataDisplay()
Dim str As String = DisplayD
Dim cmd As New SqlCommand(str, con)
Dim Ds As New DataSet()
Dim da As New SqlDataAdapter(cmd)
da.Fill(Ds, Display)
End Sub
End Class
The connection method
Imports System
Imports System.Data
Imports System.Data.SqlClient
Module Connect
Public con As SqlConnection
Public Function GetConnect()
con = New SqlConnection(ConfigurationManager.ConnectionStrings("DB001").ConnectionString)
Return con
End Function
End Module
Continue reading...
I am trying to build a Web front end that will eventally be capaible of displaying each months set of data and allow for updating.
At this stage I am just trying to display data into different gridviews (gridview1 and gridview2) which will show all the bills in pay period 1 and pay period 2.
I have a stored procedure that will accept variables @month and @payper to select the month id and pay period id.
I can get the data to display but I dont want to create the same code over and over again; This is where I am stuck, creating a method or class to call the data to grid view with the different variables.
I seem to be close by the GridView1.DataSource = ds doesnt work when I try to do this as a class.
The aspx page
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Budget.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<html xmlns="http://www.w3.org/1999/xhtml
<head runat="server
<title></title>
</head>
<body>
<form id="form1" runat="server
<asp:GridView ID="GridView1" runat="server
</asp:GridView>
<asp:GridView ID="GridView2" runat="server
</asp:GridView>
</form>
</body>
</html>
Aspx.vb file
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con = GetConnect()
con.Open()
Dim str As String = "p_DisplayBills 1, 1"
Dim cmd As New SqlCommand(str, con)
Dim da As New SqlDataAdapter(cmd)
Dim Ds As New DataSet()
da.Fill(Ds, "p_DisplayBills")
GridView1.DataSource = Ds
GridView1.DataBind()
Dim str2 As String = "p_DisplayBills 1, 2"
Dim cmd2 As New SqlCommand(str2, con)
Dim da2 As New SqlDataAdapter(cmd2)
Dim ds2 As New DataSet()
da2.Fill(ds2, "p_DisplayBills")
GridView2.DataSource = ds2
GridView2.DataBind()
Dim GridView1DataDisplay As New DataDisplay
GridView1DataDisplay.Display = "p_DisplayBills"
GridView1DataDisplay.DisplayD = "p_DisplayBills 1, 2"
GridView1.DataSource = Ds
GridView1.DataBind()
con.Close()
End Sub
End Class
The Class file
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class DataDisplay
Public Property DisplayD As String
Public Property Display As String
Public Sub DataDisplay()
Dim str As String = DisplayD
Dim cmd As New SqlCommand(str, con)
Dim Ds As New DataSet()
Dim da As New SqlDataAdapter(cmd)
da.Fill(Ds, Display)
End Sub
End Class
The connection method
Imports System
Imports System.Data
Imports System.Data.SqlClient
Module Connect
Public con As SqlConnection
Public Function GetConnect()
con = New SqlConnection(ConfigurationManager.ConnectionStrings("DB001").ConnectionString)
Return con
End Function
End Module
Continue reading...