Can't get value from one function to another in Aspx page

M

mister-Ed

I'm trying to check for "No Records Found" in a repeater list control,
but my 'numrows' variable cannot be seen by the function CheckNoR ,
even tho it's public (?)

<script runat="server">
'Handle page load event
public Sub Page_Load(Sender As Object, E As EventArgs)

Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataAdapter
dim MyDataset As DataSet
dim MyTable As DataTable
dim numrows As Integer
dim sqlstr As String
sqlstr = "SELECT company,city from customers "

MyConnection = New SqlConnection("Data Source=dbase.net;Initial
Catalog=mydb;User Id=myuser;Password=mypwd;")

MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Create a Command object with the SQL statement.
MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Fill a DataSet with data returned from the database.
MyDataset = New DataSet
MyCommand.Fill(MyDataset)





' Create a new DataTable object and assign to it
' the new table in the Tables collection.


MyTable = New DataTable
MyTable = MyDataset.Tables(0)

''''tie it to my repeater control
dr.DataSource = MyTable
dr.DataBind()


MyConnection.Close

End Sub

</script>
<script runat="server">
function checkNoR(ByVal as String)
numrows = MyTable.Rows.Count
If numrows = 0 then
Response.Write("<p>No records.</p>")
End If
end function
</script>
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

mister-Ed said:
I'm trying to check for "No Records Found" in a repeater list control,
but my 'numrows' variable cannot be seen by the function CheckNoR ,
even tho it's public (?)

<script runat="server">
'Handle page load event
public Sub Page_Load(Sender As Object, E As EventArgs)

Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataAdapter
dim MyDataset As DataSet
dim MyTable As DataTable

MyTable is a local variable in the Page_Load method.
dim numrows As Integer

numrows is a local variable in the Page_Load method.
dim sqlstr As String
sqlstr = "SELECT company,city from customers "

MyConnection = New SqlConnection("Data Source=dbase.net;Initial
Catalog=mydb;User Id=myuser;Password=mypwd;")

MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Create a Command object with the SQL statement.
MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Fill a DataSet with data returned from the database.
MyDataset = New DataSet
MyCommand.Fill(MyDataset)





' Create a new DataTable object and assign to it
' the new table in the Tables collection.


MyTable = New DataTable
MyTable = MyDataset.Tables(0)

''''tie it to my repeater control
dr.DataSource = MyTable
dr.DataBind()


MyConnection.Close

End Sub

</script>
<script runat="server">
function checkNoR(ByVal as String)
numrows = MyTable.Rows.Count

Neither numrows nor MyTable exist outside the Page_Load method.
 
M

mister-Ed

Neither numrows nor MyTable exist outside the Page_Load method.

Well, yes, I need to find a way to make them available in the CheckNoR
function without having to re-declare all the ADO objects and
'numrows' and re-assign values
thanx
Ed
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

mister-Ed said:
Well, yes, I need to find a way to make them available in the CheckNoR
function without having to re-declare all the ADO objects and
'numrows' and re-assign values
thanx
Ed

Declare them as member variables in the page class.
 

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