0

I'm just starting out looking at asp.net. I've got this code that works in VB, but not in asp.

I've put this in the page_load:

Dim db_con As SqlConnection, ssql As String, db_cmd As SqlCommand, rdr As SqlDataReader
    db_con = New SqlConnection("Data Source=myServer;Initial Catalog=processes;User Id=usrID;Password=mypwd;")
    db_cmd = New SqlCommand()
    ssql = "SELECT * FROM command_table_links WHERE command_id = 1"
    db_con.Open()
    db_cmd.Connection = db_con
    db_cmd.CommandText = ssql
    db_cmd.CommandType = Data.CommandType.Text

    rdr = db_cmd.ExecuteReader()
    rdr.Read()
    If rdr.HasRows Then
        lblTest.Text = "It connected"
    Else
        lblTest.Text = "No Connection"
    End If

    rdr.Close()
    db_con.Close()

Any idea why this wouldn't work in asp.net? The issue is that the label is blank. In vb.net as soon as the form is shown, the lable says "It connected".

Kon
  • 27,113
  • 11
  • 60
  • 86
spuppett
  • 547
  • 10
  • 26
  • Have you verified that your Page_Load method is being run? Partial methods are easy to mess up without the compiler warning you about it. – StriplingWarrior Jul 01 '11 at 20:31
  • No, I hadn't. I just put a lblTest.Text = "Hello, World!" before anything else, and it didn't show up. What makes this a partial method and what could be messing it up? The label is in a form and everything has a runat="server". – spuppett Jul 01 '11 at 20:35
  • 2
    you set a break point to check the execute get to this code ? – Simon Thompson Jul 01 '11 at 20:45
  • 1
    All the `Page_...` methods are partial methods. It means that if you don't include them, the compiler can pretend they don't exist and never get called, but if you do include them, they will be called. But you have to make sure the signature matches exactly. For example, using C#, it must be: `protected void Page_Load(object sender, EventArgs e)`. I don't know whether capitalization matters in VB.NET. Do as Simon Says (hehe), and set a break point in the code to see whether the method is even being run. – StriplingWarrior Jul 01 '11 at 21:56

1 Answers1

1

it must be:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

SAIF
  • 189
  • 1
  • 6