使用vba从SQL Server数据库读取值

时间:2016-11-07 22:00:49

标签: sql-server vba

我正在使用vba studio,并希望从sql数据库中读取一些值。

这是我的代码:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class log
    Dim usuariovb As String
    Dim passwordvb As String

    Private Sub exe_log_Click(sender As Object, e As EventArgs) Handles exe_log.Click
        usuariovb = txt_user.Text
        passwordvb = txt_pw.Text

        Dim sConnectionString As String = "Server=MXD071352\SQLEXPRESS; Database=CALLC; User Id=sa;Password=Kernmic1"
        Using objConn As New SqlConnection(sConnectionString)
            Dim comando As New SqlCommand("SELECT Contraseña from Usuarios WHERE Usuario = '" & usuariovb & "';", objConn)
            objConn.Open()
            Dim lector As SqlDataReader = comando.ExecuteReader()
            Try
                While lector.Read()
                    Console.WriteLine(String.Format("{0}, {1}", lector(0), lector(2)))
                End While
            Finally
                lector.Close()
            End Try
        End Using
    End Sub

你可以帮助我,因为我没有得到结果

0 个答案:

没有答案