Results 1 to 6 of 6

Thread: Filling in TextBox values from a database

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    28

    Filling in TextBox values from a database

    Hey guys, I am kind of new to VB.NET programming. Right now I am trying to fill in a textbox field with a value from an access database. The error I am getting is that the values are not of the same type. Do I need to do some converting before I can fill in the values? Below is my code. Thank you!!!

    Dim recset2
    Dim sqlstament2
    Dim Conn2
    recset2 = CreateObject("ADODB.Recordset")
    Conn2 = CreateObject("ADODB.Connection")
    Conn2.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\test.mdb")
    sqlstament2 = "SELECT name FROM testing"
    recset2.Open(sqlstament2, Conn2, 1, 3)
    namevalue = recset2.fields("name")
    phonevalue = recset2.fields("phone")
    useridvalue = recset2.fields("userid")
    followupvalue = recset2.fields("followup")
    problemvalue = recset2.fields("problem")

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Filling in TextBox values from a database

    YOu may need to qualify things a bit more:

    phonevalue.text = .....

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Filling in TextBox values from a database

    You are only selecting the name in the query
    VB Code:
    1. sqlstament2 = "SELECT name FROM testing"

    try selecting each one, separated by comma's, or select them all:

    VB Code:
    1. sqlstament2 = "SELECT * FROM testing"

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    28

    Re: Filling in TextBox values from a database

    I just put that in, thanks for noticing that. However, the error I am getting is
    Conversion from type 'Field' to type 'String' is not valid.

    Not sure why its considering the type of the value in the database a "field"

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Filling in TextBox values from a database

    try

    namevalue = recset2.fields("name").Value


    although I have to say not only are you using old DB connection objects (ADODB) you are also using late binding (CreateObject)

    these are both rather frowned upon in the .NET world..

    You sould be using early binding with option strict on, and ADO.NET

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    28

    Re: Filling in TextBox values from a database

    Thank you. The .value option worked

    I know about the old DB connection objects etc. I was just trying to get a quick program up and running and I am not as familar with ADO.NET as I should be.

    Thank you all very much!!!!!


    P.S. - I have been on this website all of 1 hour and I love it!!!

Posting Permissions

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



Click Here to Expand Forum to Full Width