admin管理员组文章数量:1308118
I am trying to migrate my excel userform that connects to an access database, to WinForms VB.Net.
So far I've gotten rid of most of the errors, but I can't seem to display the result of my SQL query into the textbox.
Here is my code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As Object
Dim rs As Object
Dim db As String
Dim sql As String
con = CreateObject("ADODB.Connection")
rs = CreateObject("ADODB.Recordset")
db = "C:\Users\Dennis\Documents\Blending & Filling\Basis Olie Lossing\Base Oils.accdb"
sql = "Select * from [Planning] where [Bestelbon] = " & Me.txtBestelbon.Text & ""
con.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & db)
rs.Open(sql, con)
Me.txtProduct.Text = rs(7)
rs = Nothing
con.Close
con = Nothing
End Sub
Keep getting error "Conversion from type 'Field' to type 'String' is not valid"
I am trying to migrate my excel userform that connects to an access database, to WinForms VB.Net.
So far I've gotten rid of most of the errors, but I can't seem to display the result of my SQL query into the textbox.
Here is my code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As Object
Dim rs As Object
Dim db As String
Dim sql As String
con = CreateObject("ADODB.Connection")
rs = CreateObject("ADODB.Recordset")
db = "C:\Users\Dennis\Documents\Blending & Filling\Basis Olie Lossing\Base Oils.accdb"
sql = "Select * from [Planning] where [Bestelbon] = " & Me.txtBestelbon.Text & ""
con.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & db)
rs.Open(sql, con)
Me.txtProduct.Text = rs(7)
rs = Nothing
con.Close
con = Nothing
End Sub
Keep getting error "Conversion from type 'Field' to type 'String' is not valid"
Share Improve this question edited Feb 3 at 20:00 Don Quixote asked Feb 3 at 19:57 Don QuixoteDon Quixote 111 silver badge3 bronze badges 7- This might help stackoverflow/questions/57326820/… – Bart McEndree Commented Feb 3 at 19:59
- Is there a particular reason that you're using ADO instead of ADO.NET? – It all makes cents Commented Feb 3 at 20:06
- The following may be of interest: Create a simple data application by using ADO.NET, stackoverflow/a/77949790/10024425, stackoverflow/a/70484316/10024425 – It all makes cents Commented Feb 3 at 20:17
- I simply copy/pasted my code over from vba excel to winforms vb – Don Quixote Commented Feb 3 at 20:17
- Didn't even know there was an ado version – Don Quixote Commented Feb 3 at 20:17
1 Answer
Reset to default 2You want rs.Fields(7).Value which is a string, not rs(7) which is a field.
本文标签: WinForm VBNet trying to search access databaseStack Overflow
版权声明:本文标题:WinForm VB.Net trying to search access database - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741800856a2398214.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论