Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how is it in asp.net?

    hi all,
    as in asp, we used to create recordsets and then use it to call the database field names to get the value rite? the code is something like this :

    Code:
    Dim val
    set DBRecordset = Server.CreateObject("ADODB.Recordset")
    DBRecordset.open SQLText, DBConnection, adOpenDynamic
    
    val = DBRecordset("TableFieldName")
    so how is it in asp.net? i just dunno the syntax...can someone guide me?? in desperate need of help now...thanking u all in advance...
    Warm Regards,
    Mivec

  • #2
    Regular Coder Freon22's Avatar
    Join Date
    May 2005
    Location
    USA
    Posts
    287
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Wow you are going to be having fun. VB.net 2.0 is so much better then vbscript. I remember using my recordset to fill variables for display, inserts and update. But even back then I only used the recordset for display. All inserts, updates, and deletes I did with SQL statements.

    But now you can databind you can use datagrids, and you also have the datareader. The datareader works a little like our recordset but it only reads oneway. No moving back and forward but I use the datareader kinda like I used the recordset. Like the code below, in it I am reading the information from the database into textboxs. I could just as easily be reading it into lables for display.
    Code:
    Dim reader As SqlDataReader
    
                'Try to open database and read infromation.
                Try
                    con.Open()
                    reader = cmd.ExecuteReader()
                    reader.Read()
    
                    'Fill the controls.
                    txtID.Text = reader("nameid").ToString()
                    firstName.Text = reader("first_name").ToString()
                    lastName.Text = reader("last_name").ToString()
                    Restriction.Text = reader("restriction").ToString()
                    Cost.Text = FormatCurrency(reader("cost"), 0).ToString()
                    Speed.Text = reader("speed").ToString()
                    address.Text = reader("address").ToString()
                    city.Text = reader("city").ToString()
                    state.Text = reader("state").ToString()
                    zip.Text = reader("zip").ToString()
                    reader.Close()
                    lblResults.Text = ""
    
                Catch err As Exception
                    lblResults.Text = "Error in reading information into text boxs. "
                    lblResults.Text &= err.Message
                Finally
                    con.Close()
                End Try
    Get a good book and read it took me a while to make the conection on how asp.net OOP works. But once you get it you will see how much better and you will be able to do so much more with it.

    Happy Programming!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •