1 Replies - 601 Views - Last Post: 19 May 2016 - 06:36 AM

#1 alobi  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

value of type string can't be connverted to syst.data.oledb.oledbc

Posted 18 May 2016 - 11:19 PM

Good morning
I am trying to connect to an access database, but I keep getting the following error message,value of type string can't be converted to system.data.oledb.oledbconnection. could someone please help me I very new weak with database connection

 Private Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click
        Dim myconnection As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Vb.Net Security\SecurityGuard\SecurityGuardmdb.accdb;Persist Security Info=False"
        Dim conn As New OleDbConnection
        conn.ConnectionString = myconnection


        conn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [usertbl] WHERE [username] = '" & txtusername.Text & "' AND [password] = '" & txtpassword.Text & "'", myconnection)
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        ' The following variable hold true if user is found atherwise it holds false


Is This A Good Question/Topic? 0
  • +

Replies To: value of type string can't be connverted to syst.data.oledb.oledbc

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13400
  • View blog
  • Posts: 53,478
  • Joined: 12-June 08

Re: value of type string can't be connverted to syst.data.oledb.oledbc

Posted 19 May 2016 - 06:36 AM

Well, yeah. Look at the 'new' options for oledbcommand.
https://msdn.microso...=vs.110%29.aspx

They take connection objects and not string objects. Fix line 8.
03	       Dim conn As New OleDbConnection


08	       Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [usertbl] WHERE [username] = '" & txtusername.Text & "' AND [password] = '" & txtpassword.Text & "'", myconnection)

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1