VB怎么连接数据库...急!!!!!!!!!!

tengye19840704 2008-03-18 09:25:08
VB怎么连接数据库...急!!!!!!!!!!
要用户密码等.
...全文
502 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
lcsfxs 2008-03-18
'连接字符串
Adodc1.ConnectionString = "driver={sql server};server=" + Trim(server) + ";uid=" + Trim(user) + ";pwd=" + Trim(password) + ";database=erp1"
'查询users表中全部信息
Adodc1.RecordSource = "select * from businessman"
'用datagrid显示查询信息
Set DataGrid1.DataSource = Adodc1
回复
guyehanxinlei 2008-03-18
上GOOGLE一找一大把哟.
回复
汤漠漠 2008-03-18
如果有问题发我的tanghao83@126.com就行
回复
汤漠漠 2008-03-18
你首先建个新的数据库,然后设计个新的数据表.然后用ADO控件
Adodc1.RecordSource = "select * from table_sumdates "
Adodc1.Refresh
text1.text = adodc1.recordset.fields("字段名")
这个text1.text 就是你的用户名,然后你把text2.text的输入密码与数据库里的数据对比一下对了就进入系统,错误不能时,这样就完成了.
回复
ZOU_SEAFARER 2008-03-18
2楼给了2套代码,第1套是NET
第2套是VB
回复
daisy8675 2008-03-18
楼上的同学,那是VBNET的
回复
永恒挑战 2008-03-18
Imports System.Data

Dim sqlConnection1 As SqlClient.SqlConnection
Dim strConnect As String="data source=服务器名;initial catalog=数据库名;user id=sa;password=;"

sqlConnection1=New SqlClient.SqlConnection(strConnect)
try
sqlConnection1.open ‘打开数据库
msgbox("OK")
sqlConnection1.close ‘关闭连接,释放资源
catch ex As exception
msgBox(ex.message)
end try

###################或者
Public CNN As New ADODB.Connection
Public GclsReaderGroup As New GzReader

Public GstrMealCardReaderTabOption As String

Sub Main()
Dim strCnn As String
strCnn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=DasIcCard;Data Source=(Local)"
CNN.ConnectionString = strCnn
CNN.CursorLocation = adUseClient
CNN.Open
frmMain.Show

End Sub
'Get the CardID
Public Function GetCardID(ByVal PressworkID As String, ByVal EmpName As String) As Long
On Error GoTo Myerror
Dim strSQL As String
Dim rs As New ADODB.Recordset
Dim CardID As Long
strSQL = "select cCard.CardID From cCard inner join cEmployee on cCard.CardID=cEmployee.MainCardID"
strSQL = strSQL & " where cCard.PressWorkID='" & Trim(PressworkID) & "' and cEmployee.EmployeeName='" & Trim(EmpName) & "'"
Set rs = CNN.Execute(strSQL)

CardID = rs.Fields(0).value

GetCardID = CardID
Set rs = Nothing
Exit Function
Myerror:
MsgBox Err.Description
GetCardID = 0
Resume Next


End Function

记得给分!!!!!!!!!!!!!!!!
回复
daisy8675 2008-03-18
用一个adodc控件去连接,生成连接字符.access需要密码的话则在连接字符直接加上:Jet OLEDB:Database Password=test,SQL则直接去读字符串

引用ado2.5
下面是以access连接为例子

Public Rs As New ADODB.Recordset
Public Conn As New ADODB.Connection

Public Function MakeConn() As Boolean
Dim strConn As String

On Error GoTo err

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Datas\PhoneNo.mdb;Persist Security Info=False;Jet OLEDB:Database Password=test"
Conn.CursorLocation = adUseClient
Conn.Open strConn

MakeConn = True

Exit Function

err:
MakeConn = False
Debug.Print "连接失败!"
err.Clear

End Function
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2008-03-18 09:25
社区公告
暂无公告