连接不上accesss数据库
Imports System.data
Imports System.Data.SqlClient
Public Class 用户登录
Dim sqlcon As New SqlConnection()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As String = "data source=.;connect timeout=5;User ID=sa;Password='123';initial catalog=POS收银系统;"
sqlcon.ConnectionString = conn
sqlcon.Open()
Dim sqlcom As New SqlCommand
sqlcom.CommandText = "select * from 用户信息 where 用户名='" & TextBox1.Text & " ' and 用户密码='" & TextBox2.Text & " 'and 用户类型='" & ComboBox1.Text & " ' "
sqlcom.Connection = sqlcon
Dim myds As New DataSet
Dim myadapter As New SqlDataAdapter
myadapter.SelectCommand = sqlcom
myadapter.Fill(myds, "a")
If ComboBox1.Text = "" Then
MsgBox("请选择用户类型!", MsgBoxStyle.Information, "超市管理系统")
ElseIf myds.Tables("a").Rows.Count = 0 Then
MsgBox("用户名或密码错误,请从新输入!", MsgBoxStyle.Information, "超市管理系统")
Else
pos系统主界面.Show()
Me.Hide()
MsgBox("你好!你已成功登录!", MsgBoxStyle.Information, "超市管理系统")
End If
sqlcon.Close()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
If ComboBox1.Text = "超级管理员" Then
clearr()
Button1.Enabled = True
TextBox1.Enabled = True
TextBox2.Enabled = True
End If
If ComboBox1.Text = "普通管理员" Then
clearr()
Button1.Enabled = True
TextBox1.Enabled = True
TextBox2.Enabled = True
End If
If ComboBox1.Text = "普通员工" Then
clearr()
Button1.Enabled = False
TextBox1.Enabled = False
TextBox2.Enabled = False
pos系统主界面.Show()
Me.Hide()
MsgBox("欢迎进入!", MsgBoxStyle.Information, "超市管理系统")
End If
If ComboBox1.Text = "提货员" Then
clearr()
Button1.Enabled = True
TextBox1.Enabled = True
TextBox2.Enabled = True
End If
If ComboBox1.Text = "进货员" Then
clearr()
Button1.Enabled = True
TextBox1.Enabled = True
TextBox2.Enabled = True
End If
End Sub
Sub clearr()
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
End Class
Dim conn As String = "data source=.;connect timeout=5;User ID=sa;Password='123';initial catalog=POS收银系统;"
access没设密码 连接还要密码吗?
------解决方案--------------------
根本就不对。你这个是sql server的连接字符串。
[解决办法]
"Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=路径;Jet OLEDB:Database Password=" & PassWord + ""
[解决办法]
建议使用APP.CONFIG文件做全局配置,具体如lary_li所描述的。
[解决办法]
你先看看自己的odbc里面有没有access的驱动,好像有对应的驱动才可以调用,在看看版本
[解决办法]
connection连接完之后,用 con.state 查看一下, 或者可以用工具箱中的accessdatasource
控件鼠标连接access ,连接完之后,可以通过 accessdatasource 的属性 connectstring
查看表达式
[解决办法]
http://www.connectionstrings.com/