'读取方法:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.ListBox1.Items.Clear()
Dim StrRed As StreamReader = New StreamReader("D:\111.txt", System.Text.Encoding.Default)
While Not StrRed.EndOfStream
Me.ListBox1.Items.Add(StrRed.ReadLine())
End While
StrRed.Dispose()
End Sub
End Class
'其它读写方法:
写入:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strR As New StreamWriter("D:\111.txt", True)'参数True表示 在原来的数据上面添加,如果为False这删除原来的数据 重新写入数据
strR.WriteLine(Me.TextBox2.Text)
strR.Dispose()
End Sub
读取:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim strR As New StreamReader("D:\111.txt")
While Not strR.EndOfStream
Me.TextBox1.Text += strR.ReadLine() &vbCrLf
End While
strR.Dispose()
End Sub
你还有一段连接access数据库的代码没有。你代码里的ExecuteSQL是什么? DimExecuteSQL
As
New
ADODB.ConnectionDataPath
="你的数据库位置"ConnString
=
"Provider=Microsoft.Jet.OLEDB.4.0Data
Source="
&
DataPath
&
"Persist
Security
Info=False"
ExecuteSQL
.open
ConnString
-----------------完整代码--------------未测试---------------Private
Sub
Command1_Click()
Dim
mrc
As
ADODB.RecordsetDim
ExecuteSQL
As
New
ADODB.ConnectionDataPath
="你的数据库位置"ConnString
=
"Provider=Microsoft.Jet.OLEDB.4.0Data
Source="
&
DataPath
&
"Persist
Security
Info=False"
ExecuteSQL
.open
ConnString
txtsql
=
"select
username
from
use
where
username='"
&
Trim(Text1.Text)
&
"'"
Set
mrc
=
ExecuteSQL(txtsql)
If
mrc.EOF
=
True
Then
MsgBox
"
用户名错误!",
vbExclamation
+
vbOKOnly,
"警告"
Text1.SetFocus
Text1.SelStart
=
0
Text1.SelLength
=
Len(Text1.Text)
Exit
Sub
End
If
username
=
mrc.Fields(0)
txtsql
=
"select
username
from
use
where
password='"
&
Trim(Text2.Text)
&
"'"
Set
mrc
=
ExecuteSQL(txtsql)
If
mrc.EOF
=
True
Then
MsgBox
"
密码错误!",
vbExclamation
+
vbOKOnly,
"警告"
Text2.SetFocus
Text2.SelStart
=
0
Text2.SelLength
=
Len(Text2.Text)
Exit
Sub
End
IfMDIForm1.Show
Unload
Me
End
Sub
123456789101112131415161718192021222324252627282930313233Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &Application.StartupPath &"\Data.mdb"Dim myConn As OleDbConnection = New OleDbConnection(strConn)Dim myComm As OleDbCommand = New OleDbCommandmyComm.Connection = myConnmyComm.CommandText = "select * from 开奖结果"'Dim myReader As OleDbDataReaderDim saveComm As OleDbCommand = New OleDbCommandmyConn.Open()For i = 1 To UBound(a)saveComm.CommandText = "insert into 开奖结果 (期号,红球1,红球2,红球3,红球4,红球5,红球6,蓝球,备注) values (@期号,@红球1,@红球2,@红球3,@红球4,@红球5,@红球6,@蓝球,@备注)"saveComm.Connection = myConnsaveComm.Parameters.Clear()saveComm.Parameters.AddWithValue("@期号", a(i).qh)saveComm.Parameters.AddWithValue("@红球1", a(i).h1)saveComm.Parameters.AddWithValue("@红球2", a(i).h2)saveComm.Parameters.AddWithValue("@红球3", a(i).h3)saveComm.Parameters.AddWithValue("@红球4", a(i).h4)saveComm.Parameters.AddWithValue("@红球5", a(i).h5)saveComm.Parameters.AddWithValue("@红球6", a(i).h6)saveComm.Parameters.AddWithValue("@蓝球", a(i).lq)saveComm.Parameters.AddWithValue("@备注", a(i).bz) 'MsgBox(a(i).qh &" " &i) TrysaveComm.ExecuteNonQuery()Catch ex As ExceptionMsgBox(Err.Description)End TryNext imyConn.Close()MsgBox("写入完毕", MsgBoxStyle.Information, "提示信息")Me.Close()欢迎分享,转载请注明来源:内存溢出
评论列表(0条)