重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这是你的For语句
新干网站建设公司成都创新互联,新干网站设计制作,有大型网站制作公司丰富经验。已为新干上千多家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的新干做网站的公司定做!
For i = 0 To webtable.Rows.Count - 1
Label2.Text = "正在从远程服务器下载数据 " i "/" webtable.Rows.Count
CMD = New OleDbCommand(Dbcstr, Dbc)
CMD.ExecuteNonQuery()
webrow = webtable.Rows.Item(i)
Next
语句中Dbcstr一直没有变动过,所以你提交到数据库中的内容总是第一行。
修改如下,未调试。
Dbc.Open()
For i = 0 To webtable.Rows.Count - 1
Dim Dbcstr As String = "INSERT INTO PurchaseOrders ([PurchaseOrderID],……
Dbcstr = Dbcstr " VALUES('" webtable.rows(i).Item(0) "','" ……
'webrow.Item(0)改成webtable.rows(i).Item(0),其他一样
CMD = New OleDbCommand(Dbcstr, Dbc)
CMD.ExecuteNonQuery()
Next
conn.Close()
Dbc.Close()
软糖来告诉你吧。
VB.net中读写文件主要使用System.IO命名空间。
① 使用 File.ReadAllText 读取
Dim s As String = System.IO.File.ReadAllText("C:\a.txt")
② 使用 StreamReader 读取,注意编码格式和写入的编码保持一致。
Dim sr As StreamReader = New StreamReader("C:\a.txt", System.Text.Encoding.UTF8)
Dim s As String = sr.ReadToEnd()
sr.Close()
③ 使用 File.WriteAllText 写入,会覆盖同名的文件。
Dim 要写的内容 As String = ""
File.WriteAllText(文件路径, 要写的内容, System.Text.Encoding.UTF8)
④ 使用 StreamWriter 写入。
Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("C:\a.txt", False, System.Text.Encoding.UTF8)
sw.WriteLine(TextTB.Text)
sw.Close()
⑤ 使用 StreamWriter 追加写入。
将上面代码的第二个参数False改为True。
◆ 满意请采纳,谢谢 ◆
'窗体上放5个textBox控件,控件名依次为 TextBox1, TextBox2, TextBox3, TextBox4, TextBox5
'Button1按钮为读文件,Button2按钮为写文件
'程序第一运行时先在5个文本框中输入相应内容,点击“写文件”,以创建文件
Public Class Form1
Private textBoxArray() As TextBox
Private fileName As String
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.textBoxArray = New TextBox() {Me.TextBox1, Me.TextBox2, Me.TextBox3, Me.TextBox4, Me.TextBox5}
fileName = "csdx.txt"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If System.IO.File.Exists(fileName) True Then
MsgBox("文件不存在!,请先在文本框中输入数据,点击写文件。")
Exit Sub
End If
Dim line As String
Dim sr As IO.StreamReader = New IO.StreamReader(fileName, System.Text.Encoding.Default)
Dim I As Integer
For I = 1 To 5 Step 1
If sr.EndOfStream Then Exit For
line = sr.ReadLine
Me.textBoxArray(I - 1).Text = line
Next I
sr.Close()
sr = Nothing
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sw As IO.StreamWriter = New IO.StreamWriter(fileName, False)
Dim I As Integer
For I = 1 To 5
sw.WriteLine(Me.textBoxArray(I - 1).Text)
sw.Flush()
Next
sw.Close()
sw = Nothing
End Sub
End Class
.net应该提供了此类函数。如C#就有File.AppendAllText(filename,string)用于追加内容,File.ReadAllLine(filename)用于读取多行。
要确保有这么多行和这么多列,
dataGridView1(3, 2).Value = 123.456
写入:Dim sr As New IO.StreamWriter(Application.StartupPath "/写入的文本.txt")
sr.WriteLine("写入的内容") sr.Close()读取:If (File.Exists(Application.StartupPath "/msg.txt")) Then
Dim fm As New IO.FileStream(Application.StartupPath "/读取的文本.txt", FileMode.Open)
Dim sr As IO.StreamReader = New IO.StreamReader(fm)
Do While sr.Peek() = 0
TextBox1.Text = sr.ReadLine() (读取文本到文本框)
Loop end if