Hello all!

I am getting errors when I try to use this adodb.connection and command in my code. The error I am getting is saying that the connection and command are not defined. I read online that depending on your version of vb that you might use the "OLE" connection instead of ADODB but I am new to vb so I really don't know.

I am really confused but I posted my code below....

Please help me or direct me to any sites that might help me with this

Imports System.Text.RegularExpressions
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System

Partial Class _Default
    Inherits System.Web.UI.Page
    Private myConn As SqlConnection
    Private myCmd As SqlCommand
    Private myReader As SqlDataReader
    Private userID As String
    Private authlvl As String
    Private passwordTextBox As Object
    Private usernameTextBox As Object
    Private Password As Object
    Private overwriteExp As String
    Private Process As Object
    Private htmlusername As Object
    Private userIDIn As String
    Private passwordIn As String
    Private address As String

    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Page.IsPostBack = False Then
            ViewState.Add("usename", Request.Form("usernameTextBox").ToString())
            ViewState.Add("passwrd", Request.Form("passwordTextBox").ToString())
            checkPassword()
            AuthlvlLabel.Text = authlvl
            If authlvl = "" Then
                Response.Redirect("Error.htm")
            End If
        End If
        Password.Text = (ViewState.Item("passwrd").ToString)

        UserName.Text = userNameValed(ViewState.Item("usename").ToString)
        userID = ViewState.Item("usename").ToString

        overwriteExp = ""
        If AuthlvlLabel.Text = "admin" Then
            address = "Admin.aspx?un=" + htmlusername + "&al=" + AuthlvlLabel.Text
            AdminButton.Visible = True
        End If
    End Sub
    Sub checkPassword()


        Dim conn As New SqlConnection("Data Source=trtr-tye-SQL1;Initial Catalog=import;User ID=sa;Password=tredtade")
        Dim userIDIn As String = ViewState.Item("usename").ToString
        Dim passwordIn As String = ViewState.Item("passwrd").ToString
        Dim sql As String = "SELECT auth_lvl FROM user_verification WHERE userID = '" & userIDIn & "' AND password = '" & passwordIn & "';"
        Dim cmd = New SqlCommand(sql, conn)
        authlvl = ""

        Try
            conn.Open()
            Dim result As SqlDataReader = cmd.ExecuteReader()
            Do While (result.Read())
                authlvl = result.GetString(0)
            Loop
            result.Close()
            conn.Close()
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try

    End Sub
    Function userNameValed(ByVal sUserNameIn As String) As String


        Dim oCon As ADODB.Connection, oCommand As ADODB.Command
        Dim oRs As Object, oUsr As Object

        Dim sUserName As String = sUserNameIn
        oCon = CreateObject("ADODB.Connection")
        oCon.Provider = "ADsDSOObject"


        oCon.Open("Active Directory Provider")
        oCommand = CreateObject("ADODB.Command")
        oCommand.ActiveConnection = oCon
        oCommand.CommandText = "<LDAP://OU=Accounts,DC=pr,DC=tos,DC=topple,DC=com>;(&(objectClass=user)(samAccountName=" & sUserName & "));ADsPath, objectclass;subtree"
        oRs = oCommand.Execute
        oUsr = GetObject(oRs.Fields("AdsPath").Value)

        userNameValed = oUsr.FirstName & " " & oUsr.LastName
        htmlusername = oUsr.FirstName & "ZOZ" & oUsr.LastName
    End Function

    Protected Sub Browse_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim FileName As String = "ExporterOutput.txt"
        Dim FilePath As String = "C:/Users/My Documents/ExporterOutput.txt"
        Dim response As HttpResponse = HttpContext.Current.Response
        response.ClearContent()
        response.Clear()
        response.ContentType = "text/plain"
        response.AddHeader("Content-Disposition", ("attachment; filename = " & FileName & ";"))
        response.TransmitFile(FilePath)
        response.Write("Username:")
        response.Write("  ")
        response.Write("Authorization Level:")
        response.Write("  ")
        response.Write("Database:")
        response.Write("  ")
        response.Write("Dataset:")
        response.Write("  ")
        response.Write("SGMLid:")
        response.Write(Date.Now.ToLongDateString() & " " & Date.Now.ToLongTimeString())
        response.Flush()
        response.End()

    End Sub
    Protected Sub Export_Click(ByVal sender As Object, ByVal e As System.EventArgs)

   Process.Start("Z:\tools\bin\")

    End Sub
    Protected Sub AdminButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Redirect(address)
    End Sub
    Protected Sub ClearText_Click(ByVal sender As Object, ByVal e As EventArgs)
        sgml.Text = String.Empty
        Output.Text = String.Empty

    End Sub

    Protected Sub enableButtons()
        DropDownList1.Enabled = True
        DropDownList2.Enabled = True
        Export.Enabled = True
    End Sub

End Class
Imports MySql.Data.MySqlClient
Imports System.Data

Public Class classDatabaseRead

    Private sqlConnection As New MySqlConnection
    Private sqlCommand As New MySqlCommand
    Public sqlReader As MySqlDataReader

    Private stringConnection As String = "SERVER=Gemstore;DATABASE=yourdatabase;PORT=3306;UID=user;PWD=password~;"

    Public Sub New(ByVal stringQuery As String)
        Try

            sqlConnection.ConnectionString = stringConnection
            sqlConnection.Open()

            sqlCommand.Connection = sqlConnection
            sqlCommand.CommandText = stringQuery

            sqlReader = sqlCommand.ExecuteReader()

        Catch ex As Exception

            MsgBox(ex.toString)
            sqlCommand.Connection.Close()
            sqlConnection.Close()

        End Try
    End Sub

    Public Sub closeRead()
        sqlReader.Close()
        sqlCommand.Connection.Close()
        sqlConnection.Close()
    End Sub
End Class

then in a form or whatever you are calling it from

DIM Query as string = "SELECT auth_lvl FROM user_verification WHERE userID = '" & userIDIn & "' AND password = '" & passwordIn & "';"
 
DIM r as classdatabaseread = new classdatabaseread(query)
while r.sqlreader.read
auth = r.sqlreader.getstring(r.sqlreader.getordinal("auth_lvl"))
end
r = nothing

i saw that you are using the sqlreader, not mysqlreader sorry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.