0

I'm trying to put this code in a textbox, it seems correct. However, the "OldDbConnection" and ".Open" are underlined red. Am I missing something or doing something wrong?

OleDbConnection conn = new 
    OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;
Persist Security Info=False;");

    try
    {
        conn.Open();
        MessageBox.Show("Connected");


    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
  • do you have the appropriate namespace? – Daniel A. White Oct 08 '14 at 23:51
  • @DanielA.White actually that's the error that is appearing. – CaptainBadass Oct 08 '14 at 23:51
  • Try to search on the error message and see what you can find!? – Will Marcouiller Oct 08 '14 at 23:55
  • @WillMarcouiller namespace does not exist. something like that. am I missing something? – CaptainBadass Oct 09 '14 at 00:02
  • I guess, look what I found: [Type or namespace does not exist](https://www.google.ca/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=namespace%20does%20not%20exist) – Will Marcouiller Oct 09 '14 at 00:04
  • First, add the error message in your question so that others may clearly understand what's going on. Saying a word is underlined is not enough. Second, this means a reference to a namespace is missing. See @DanielA.White's answer. Otherwise, look for yourself at plenty of resources found by typing "Type or namespace does not exist" (see previous comment). – Will Marcouiller Oct 09 '14 at 00:17
  • See this [SO Question - Type or namespace does not exist](http://stackoverflow.com/questions/5567945/type-or-namespace-name-does-not-exist) found in my Google Search. – Will Marcouiller Oct 09 '14 at 00:19

2 Answers2

1

Add a using System.Data.OleDb to the top of your file.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
0
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbDataReader

Public Class Form1
    Dim provider As String
    Dim dataFile As String
    Dim connString As String
    Dim myConnection As OleDbConnection = New OleDbConnection





    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        provider = "Provider =Microsoft.ACE.OLEDB.12.0;Data Source="
        dataFile = "C:\Users\ANNALIZA\Desktop\New folder (4)\JABOYY1.accdb"
        connString = provider & dataFile
        myConnection.ConnectionString = connString
        myConnection.Open()


        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [ADMIN] WHERE [userName] = '" & TextBox1.Text & "' AND [userPassword] = '" & TextBox2.Text & "'", myConnection)
        Dim userFound As Boolean = False
        Dim FirstName As String = ""
        Dim LastName As String = ""
        Dim dr As OleDbDataReader = cmd.ExecuteReader




        While dr.Read
            userFound = True
            FirstName = dr("FirstName").ToString
            LastName = dr("LastName").ToString

        End While
        If userFound = True Then
            Form2.Show()
            Form2.Label1.Text = "Welcome" & FirstName & " " & LastName
        ElseIf TextBox1.Text = "" And TextBox2.Text = "" Then
            MsgBox("No such username and password found! Input first before you click LOG IN!", MsgBoxStyle.Critical, "Warning")
            Me.Show()



        ElseIf MsgBox("Sorry username and password not found!LOGIN FAILED", MsgBoxStyle.Exclamation, "Invalid Log in") Then
            TextBox1.Text = ""
            TextBox2.Text = ""
            Me.Show()

        End If




    End Sub
Raviteja
  • 3,399
  • 23
  • 42
  • 69
  • add at the top Imports System.Data.OleDb Imports System.Data.OleDb.OleDbDataReader Public Class Form1 Dim provider As String Dim dataFile As String Dim connString As String Dim myConnection As OleDbConnection = New OleDbConnection – Jhayboy Mar 30 '16 at 04:29