Hi guys, I've stucked with this error "Compiler Error Message: BC30451: Name 'DataSet1' is not declared.". I am using Vb.Net code behind and bind data to the datagrid. I am using stored procedure/SQL Server 2000/IIS5.0. -------------------------------------------------------------------------------------------
Source Error: Line 13: Source File: http://localhost/WebApplication2/WebForm1.aspx Line: 13 ------------------------------------------------------------------------------------------- Code from web form page (WebForm1.aspx): <form id="Form1" method="post"
runat="server"> </form> ----------------------------------------------------------------------------------------------------- Here's VB.Net code behind: Imports System.Data.SqlClient Public Class WebForm1 Inherits System.Web.UI.Page #Region " Web Form Designer
Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid Protected WithEvents Label1 As System.Web.UI.WebControls.Label 'NOTE: The following
placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object 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 Dim SqlConnection1
As SqlConnection = New SqlConnection("server=(local);database=Test;user id=sa; pwd=;") Dim SqlCmd1 As SqlCommand = New SqlCommand("Proc_ViewCustomers", SqlConnection1) SqlCmd1.CommandType = CommandType.StoredProcedure Dim SqlAdapter1 As SqlDataAdapter = New
SqlDataAdapter SqlAdapter1.SelectCommand = SqlCmd1 Dim DataSet1 As DataSet SqlAdapter1.Fill(DataSet1) DataGrid1.DataSource = DataSet1 DataGrid1.DataBind() End Sub End Class --------------------------------------------------------------------------------------
Any suggestion please... I'm running out of idea... Thank you very much, Kate
Still no luck, Justin. It work fine if I use web form designer to bind data, but not with manual code on run-time. I'm curious. Any helps, guys? Thank you, Kate
Hi Justin, It gives new error "dataset can't be bull". Anyway, I use web form designer to generate data and it's work, although the code behind is really wordy. The trick is web form has to set value of data components in Sub InitializeComponent, and then call
InitializeComponent from Page_Init and then Fill the dataset and bind to DataGrid on Page_Load. And you were absolutely right about web from try to make reference to local varaible in code behind. This following code declare all data component variables as
Protected. Here's the code behind: --------------------------------------------------------------------------------- Imports System.Data.SqlClient Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter Protected WithEvents DataSet1 As WebApplication2.DataSet1 Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
'Required by the Web Form Designer. Private designerPlaceholderDeclaration As System.Object Private Sub InitializeComponent() Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand Me.SqlConnection1
= New System.Data.SqlClient.SqlConnection Me.DataSet1 = New WebApplication2.DataSet1 CType(Me.DataSet1, System.ComponentModel.ISupportInitialize).BeginInit() ' 'SqlDataAdapter1 ' Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1 Me.SqlDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Proc_ViewCustomers", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Cust_Id", "Cust_Id"), New System.Data.Common.DataColumnMapping("Title",
"Title"), New System.Data.Common.DataColumnMapping("First_Name", "First_Name"), New System.Data.Common.DataColumnMapping("Last_Name", "Last_Name"), New System.Data.Common.DataColumnMapping("Title_Id", "Title_Id"), New System.Data.Common.DataColumnMapping("Title_Desc",
"Title_Desc")})}) ' 'SqlSelectCommand1 ' Me.SqlSelectCommand1.CommandText = "[Proc_ViewCustomers]" Me.SqlSelectCommand1.CommandType = System.Data.CommandType.StoredProcedure Me.SqlSelectCommand1.Connection = Me.SqlConnection1 Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing)) CType(Me.DataSet1, System.ComponentModel.ISupportInitialize).EndInit()
' 'SqlConnection1 ' Me.SqlConnection1.ConnectionString = "workstation id=T1;packet size=4096;user id=sa;data source=S1;persist security inf" & _ "o=False;initial catalog=Test" ' 'DataSet1 ' Me.DataSet1.DataSetName = "DataSet1" Me.DataSet1.Locale = New System.Globalization.CultureInfo("en-US")
End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init InitializeComponent() End Sub Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SqlDataAdapter1.Fill(DataSet1)
DataGrid1.DataBind() End Sub End Class ----------------------------------------------------------------------------- .aspx page: <form id="Form1" method="post" runat="server"> </form> ---------------------------------------------------------------------------------
Anyway, just for learning purpose. I will explore alternative way(and maybe shorter :) to use ADO.Net to publish data onto web form... Thank you very much! Kate
kates
Member
15 Points
3 Posts
Compiler Error BC30451-"Name ... Not Declared" - Web Form to Code Behind
Oct 14, 2003 12:41 PM|LINK
master4eva
Star
13635 Points
2719 Posts
Re: Compiler Error BC30451-"Name ... Not Declared" - Web Form to Code Behind
Oct 14, 2003 06:03 PM|LINK
kates
Member
15 Points
3 Posts
Re: Compiler Error BC30451-"Name ... Not Declared" - Web Form to Code Behind
Oct 14, 2003 07:42 PM|LINK
master4eva
Star
13635 Points
2719 Posts
Re: Compiler Error BC30451-"Name ... Not Declared" - Web Form to Code Behind
Oct 14, 2003 08:03 PM|LINK
kates
Member
15 Points
3 Posts
Re: Compiler Error BC30451-"Name ... Not Declared" - Web Form to Code Behind
Oct 14, 2003 09:09 PM|LINK