VB程序员博客
VB怎么连接数据库…急!!!!!!!!!!
要用户密码等.
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
记得给分!!!!!!!!!!!!!!!!
楼上的同学,那是VBNET的
2楼给了2套代码,第1套是NET
第2套是VB
你首先建个新的数据库,然后设计个新的数据表.然后用ADO控件
Adodc1.RecordSource = "select * from table_sumdates "
Adodc1.Refresh
text1.text = adodc1.recordset.fields("字段名")
这个text1.text 就是你的用户名,然后你把text2.text的输入密码与数据库里的数据对比一下对了就进入系统,错误不能时,这样就完成了.
如果有问题发我的tanghao83@126.com就行
上GOOGLE一找一大把哟.
'连接字符串
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
标签: , 数据库