none
Command "Provider" in VB.net Visual Studio 2015, Why have been printed in red color ?

    Question

  • Please, I need clarification about this one case.

    When I tried to write down this program source, I follow feedback by typing this code, like below

    Dim sql As String
    sql = “
    Provider=Microsoft.ACE.OLEDB.12.0;DataSource=DatabaseKu.accdb;
    Dim con As New OleDb.OleDbConnection(sql)
    con.Open()
    Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(“
    Select * from login where username ='” & TxtUsername.Text& “‘ and password='” & TxtPassword.Text& “‘”, con) ‘query untuk membaca data username dan password ‘pada database

    Note : This command with bold characters, in VB.net studio 2015 has been printed in red color. It mean that the command has been unknown by this language.

    Please tell me why this happen with this case ?

    Thursday, April 27, 2017 3:27 AM

All replies

  • This command with bold characters, in VB.net studio 2015 has been printed in red color. It mean that the command has been unknown by this language.

    You are missing some spaces.

    (“Select * from login where username ='" & TxtUsername.Text & "‘ and password='" & TxtPassword.Text& "‘", con)


    • Edited by AcamarMVP Thursday, April 27, 2017 3:35 AM fmt
    Thursday, April 27, 2017 3:34 AM
  • Hello,

    Please consider using parameters e.g.

    Public Class Sample
        Private Builder As New OleDbConnectionStringBuilder With
        {
            .Provider = "Microsoft.ACE.OLEDB.12.0",
            .DataSource = IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DatabaseKu.accdb")
        }
        Public Function ReadUserData(ByVal UserName As String, ByVal UserPassword As String) As DataTable
            Dim dt As New DataTable
            Using cn As New OleDbConnection With {.ConnectionString = Builder.ConnectionString}
                Using cmd As New OleDbCommand With {.Connection = cn}
                    cmd.CommandText =
                        <SQL>
                            SELECT * FROM LOGIN WHERE username = @UserName, [password] = @password
                        </SQL>.Value
    
                    cmd.Parameters.AddWithValue("@UserName", UserName)
                    cmd.Parameters.AddWithValue("@password", UserPassword)
                    cn.Open()
                    dt.Load(cmd.ExecuteReader)
                End Using
            End Using
    
            Return dt
    
        End Function
    End Class
    
    Note the connection points to the same folder as the executable.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, April 27, 2017 11:18 AM
    Moderator
  • Hi Muljanto,

    First please note that some spaces in the Data Source, Please refer to:

    Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Database\Database2.accdb; Persist Security Info=False;"

    and then I suggest you to use parameters, please refer to:

     Private Sub loaddate()
            Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\C#\Example(VB)\Example(VB)\Database1.accdb; Persist Security Info=False;"
            Using conn As New OleDbConnection(connectionString)
                Using comm As New OleDbCommand()
                    With comm
                        .Connection = conn
                        .CommandType = CommandType.Text
                        .CommandText = "INSERT INTO [Table] (ColumnID,ColumnName,ColumnSex,ColumnNumber) VALUES(@ColumnID,@ColumnName,@ColumnSex,@ColumnNumber)"
                        .Parameters.AddWithValue("@ColumnID", TextID.Text.ToString)
                        .Parameters.AddWithValue("@ColumnName", TextName.Text.Trim())
                        .Parameters.AddWithValue("@ColumnSex", TextSex.Text.Trim())
                        .Parameters.AddWithValue("@ColumnNumber", TextNumber.Text.Trim())
    
                    End With
                    Try
                        conn.Open()
                        comm.ExecuteNonQuery()
                        conn.Close()
                        MessageBox.Show("Successful")
                    Catch e As Exception
                        MessageBox.Show(e.Message)
                    End Try
                End Using
            End Using
        End Sub

    Hope it is helpful to you.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 28, 2017 5:45 AM
    Moderator
  • Hi MulJanto,

    Have you solved your issue now, if yes, please remember to close your thread by marking helpful post as answer, it is very beneficial to the other communities who face the same issue.

    Thanks for your understanding.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 4, 2017 7:20 AM
    Moderator