首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

vb中数据库连接-用户登录,该怎么处理

2012-12-16 
vb中数据库连接-用户登录在dr commSQL.ExecuteReader()出错,为什么,请各位帮帮忙Public Class Form1Publ

vb中数据库连接-用户登录
在dr = commSQL.ExecuteReader()
出错,为什么,请各位帮帮忙



Public Class Form1
    Public names As String
    Public pw As String
    Public i As Integer


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        names = TextBox1.Text
        pw = TextBox2.Text
        Dim conSQL As SqlClient.SqlConnection
        conSQL = New SqlClient.SqlConnection()
        conSQL.ConnectionString = "Integrated Security= true;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Initial Catalog=Database1.mdf;"
        conSQL.Open()

        Dim commSQL As SqlClient.SqlCommand
        commSQL = New SqlClient.SqlCommand()
        commSQL.Connection = conSQL
        commSQL.CommandText = "Select * from user where user='" + names + "'and password='" + pw + "'"

        Dim dr As SqlClient.SqlDataReader

        dr = commSQL.ExecuteReader()

        If dr.Read() Then
            Form2.Show()
        Else
            Form3.Show()
        End If
    End Sub
End Class

[最优解释]
检查连接字符串、sql是否正确。
[其他解释]
为什么不用LINQ?
[其他解释]
 conSQL.ConnectionString = "Integrated Security= true;Data Source=.\SQLEXPRESS;AttachDbFilename=
[其他解释]
DataDirectory
[其他解释]
没有关闭dr
[其他解释]
\Database1.mdf;Initial Catalog=Database1.mdf;"
  conSQL.Open()



我建议你先手动测试一下连接,建一个*.udl文件,双击它,先测

如果可以,这时候用记事本打开它,就可以得到一个完整的登陆string~~

热点排行