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

tengye19840704 2008-03-18 09:25:08
VB怎么连接数据库...急!!!!!!!!!!
要用户密码等.
...全文
533 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
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

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧