专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

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

发布时间:2011-06-23 14:42:20 文章来源:www.iduyao.cn 采编人员:星星草
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~~
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: