vb.net如何创建mdb文件并设置密码
首先在项目的VB.NET界面,使用菜单【项目】--【添加引用】--【COM】
10年积累的做网站、网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先制作网站后付款的网站建设流程,更有歙县免费网站建设让你可以放心的选择与我们合作。
选择 Microsoft ADO Ext. 2.x for DDL and Security
然后单击【确定】,完成引用。
完整代码如下:
Imports ADOX
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'创建空的access数据库文件--数据库文件.mdb,密码为123
Dim Mycat As Catalog = New Catalog()
Mycat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source= 数据库文件.mdb;Jet OLEDB:Database Password=123")
'以下代码创建一个名为“实验数据表”
Dim MyTable As ADOX.Table = New ADOX.Table '定义新表
MyTable.Name = "实验数据表" '表命名
'给表“实验数据表” 创建一个字符串字段,字段名“姓名”
MyTable.Columns.Append("姓名", , ADOX.DataTypeEnum.adWChar)
'给表“实验数据表” 创建一个整数字段,字段名“学号”
MyTable.Columns.Append("学号", ADOX.DataTypeEnum.adInteger) '追加一个数字型字段
'给字段“学号”创建一个主键“PimaryKey_Field”
MyTable.Keys.Append("学号", ADOX.KeyTypeEnum.adKeyPrimary, "学号")
Mycat.Tables.Append(MyTable) '把所有的新字段追加到表
MyTable = Nothing
Mycat = Nothing
End Sub
End Class
VB.net中如何调用带密码的Access数据库
"Provider=Microsoft.jet.oledb.4.0;data source=" "含路径的数据库文件" ";Persist Security Info=False
;jet oledb:database password=" "数据库密码"
VB.Net 怎么验证 SQL2008 数据库的ID与密码
基础类库:
Imports Microsoft.VisualBasic
'执行Access语句的封装类。
Public Class AccessExecClass
Private conn As Data.OleDb.OleDbConnection
Private cmd As Data.OleDb.OleDbCommand
'创建类对象,并连接到数据库。
Sub New()
If openAccess Then
Else
msgbox("open Access Fail.")
End If
End Sub
'创建类对象,并连接到数据库。 '输入带目录名称的数据库文件名称:dbFileName,例如:“\DB数据库\企业数据库.aspx”
Sub New(ByVal dbFileName As String)
If OpenAccess(dbFileName) Then
Else
MsgBox("open Access Fail.")
End If
End Sub
Function OpenAccess() As Boolean
OpenAccess = False
'检验用户的帐号密码是否正确
Dim provider As String '= ConfigurationManager.ConnectionStrings("ConnectionString").ProviderName
provider = "Provider=Microsoft.Jet.OLEDB.4.0"
Dim database As String
database = "Data Source=" System.Web.HttpContext.Current.Server.MapPath("\数据库.aspx") ";Persist Security Info=true"
conn = New Data.OleDb.OleDbConnection(provider ";" database)
conn.Open()
OpenAccess = True
End Function
Function OpenAccess(ByVal dbFileName As String) As Boolean
OpenAccess = False
'检验用户的帐号密码是否正确
Dim provider As String '= ConfigurationManager.ConnectionStrings("ConnectionString").ProviderName
provider = "Provider=Microsoft.Jet.OLEDB.4.0"
Dim database As String
database = "Data Source=" System.Web.HttpContext.Current.Server.MapPath(dbFileName) ";Persist Security Info=true"
conn = New Data.OleDb.OleDbConnection(provider ";" database)
conn.Open()
OpenAccess = True
End Function
'关闭数据库。
Sub CloseAccess()
cmd = Nothing
conn.Close()
End Sub
'执行一条Access语句,执行成功就返回True。
Function ExecAccessString(ByVal AccessStr As String) As Boolean
cmd = New Data.OleDb.OleDbCommand(AccessStr, conn)
cmd.ExecuteNonQuery()
'Dim aa As Data.OleDb.OleDbDataReader = cmd.ExecuteReader
ExecAccessString = True
End Function
'返回读取到的数据,注意是用地址传递方式返回
Sub ExecAccessString(ByVal AccessStr As String, ByRef AccessReader As Data.OleDb.OleDbDataReader)
cmd = New Data.OleDb.OleDbCommand(AccessStr, conn)
cmd.ExecuteNonQuery()
AccessReader = cmd.ExecuteReader
End Sub
End Class
登陆代码:
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim wl As New WebLog '用户登录记录开始,仅对购买了Log 功能的用户,才开放此功能,否则不会实际记录Log
Dim sql As String
Dim aDB As New AccessExecClass
Dim mypw As String
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
Label4.Visible = False
'没有输入时,不能进行登陆
If TextBox1.Text = "" Then
Label1.Visible = True
Return
End If
If TextBox2.Text = "" Then
Label2.Visible = True
Return
End If
If TextBox3.Text = "" Then
Label3.Visible = True
Return
End If
If TextBox3.Text = TextBox4.Text Then
Else
Label3.Visible = True
Return
End If
Dim iRnd As Integer = Rnd(10) * 100
TextBox3.Text = ""
TextBox4.Text = iRnd.ToString
'Dim iRnd As Integer = Rnd(10) * 100
'注意:此处需要加入防止注入分析,包含'的肯定是特别语句,讲拒绝.
If TextBox1.Text.IndexOf("'") 0 Or TextBox2.Text.IndexOf("'") 0 Then
TextBox1.Text = "不能输入非法字符,将强制清空"
TextBox2.Text = ""
Else
Dim pw As New MD5EnCode(13, 19) ' '2次加密
sql = "select 权限组号,ID , 密码 from 编辑人数据 where 编辑姓名='" + TextBox1.Text + "'"
Dim aa As Data.OleDb.OleDbDataReader '= cmd.ExecuteReader
aDB.ExecAccessString(sql, aa)
If aa.Read() Then
'密码正确()
'sql = aa(2)'需要特别注意:只能单向解密,不能直接转换
mypw = pw.simDeCode(pw.simDeCode(aa(2)))
If TextBox2.Text = mypw Then
Session("LOGIN_Name") = TextBox1.Text '设置登录后的用户名称
Session("Login_Group") = aa(0) 'cmd.ExecuteScalar '设置登录后的权限级别
Session("Login_ID") = aa(1) 'cmd.ToString
'cmd = Nothing
'conn.Close()
Call wl.NewLog("登录", "管理员成功登录")
Response.Redirect("../WebManages/Default.ASPX")
Else
'密码错误()
sql = sql.Replace("'", "【单引号】")
sql = sql.Replace(",", "【逗号】")
Call wl.NewLog("登录", "管理员失败的登录", TextBox1.Text, sql.Replace("""", "【双引号】"), "")
Label4.Visible = True
End If
Else
'密码错误()
sql = sql.Replace("'", "【单引号】")
sql = sql.Replace(",", "【逗号】")
Call wl.NewLog("登录", "管理员失败的登录", TextBox1.Text, sql.Replace("""", "【双引号】"), "")
Label4.Visible = True
End If
End If
End Sub
分享名称:vb.net数据库密码 vb和数据库用户名和密码
地址分享:http://lswzjz.com/article/dooeped.html