|
-
Nov 23rd, 2005, 03:09 PM
#1
Thread Starter
Junior Member
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")
-
Nov 23rd, 2005, 03:19 PM
#2
PowerPoster
Re: Filling in TextBox values from a database
YOu may need to qualify things a bit more:
phonevalue.text = .....
-
Nov 23rd, 2005, 03:21 PM
#3
Re: Filling in TextBox values from a database
You are only selecting the name in the query
VB Code:
sqlstament2 = "SELECT name FROM testing"
try selecting each one, separated by comma's, or select them all:
VB Code:
sqlstament2 = "SELECT * FROM testing"
-
Nov 23rd, 2005, 03:28 PM
#4
Thread Starter
Junior Member
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"
-
Nov 23rd, 2005, 03:39 PM
#5
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
-
Nov 23rd, 2005, 03:44 PM
#6
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|