下面给你点别的相关知识,仅供参考.
小写字母的ascii值在90到116 之间
用rnd随机函数获得这之间的值,在使用chr或者其他函数转换成字符类型,
dim filename as string
filename="D:\VB\123"+chr(rnd()*90+26)+chr(rnd()*90+26)+chr(rnd()*90+26)+".txt"
没有测试过,思路应该是对的
'SQL版
Private Con As String = "<连接字符串>"'<连接字符串>可以自动生成
Private connection As SqlClient.SqlConnection
Private command As SqlClient.SqlCommand
Public Function DBopen() As Boolean '打开数据库
Try
connection = New SqlClient.SqlConnection
connection.ConnectionString = Con
connection.Open()
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
Public Function DBclose() As Boolean '关闭数据库
Try
connection = New SqlClient.SqlConnection
connection.ConnectionString = Con
connection.Close()
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
'Access版
Private Con As String = "<连接字符串>"'<连接字符串>可以自动生成
Private connconnection As OleDb.OleDbConnection
Private conncommand As OleDb.OleDbCommand
Public Function DBopen() As Boolean
Try
Me.connconnection = New OleDb.OleDbConnection
Me.connconnection.ConnectionString = Con
connconnection.Open()
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
Public Function DBclose() As Boolean
Try
Me.connconnection = New OleDb.OleDbConnection
Me.connconnection.ConnectionString = Con
connconnection.Close()
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
两者没什么大区别
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)