代码:
'''
Dim s As String = e.Form.Controls("CheckedComboBox指定股piao").Value
Dim nms() As String = s.split(",")
Dim dm,dm1 As String '沪深冠字
Dim _sr As String = Format(e.Form.Controls("DateTimePicker开始日期").value , "yyyyMMdd") '起始日期
Dim _zr As String = Format(e.Form.Controls("DateTimePicker结束日期").value , "yyyyMMdd") '结束日期
For Each nm As String In nms
Dim dr0 As DataRow = DataTables("沪深A股").Find("代码 = '" & nm & "'")
If dr0.IsNull("代码") = False Then
dm = dr0("代码")
If dm >= 600000 Then
dm1 = "0" & dm
Else
dm1 = "1" & dm
End If
End If
Dim obj_down As New System.Net.WebClient()
Dim data As String = obj_down.DownloadString("http://quotes.money.163.com/service/chddata.html?code=" & dm1 & "&start=" & _sr & "&end=" & _zr & "&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP")
data = data.Replace(vblf,"").Replace("'","''")
Dim rs() As String = data.Split(vbcr)
str = dm
For i As Integer = 1 To rs.Length - 2
Dim cs() As String = rs(i).Split(",")
If cs.Length = 15 Then
Dim pr As DataRow
With DataTables("导入数据")
pr = .SQLFind("代码 = '" & dm & "'and 日期 = '" & cs(0) & "'")
End With
If pr Is Nothing Then
Dim cmd As new SQLCommand
cmd.C
cmd.CommandText = "In sert Into 导入数据 (日期,代码,名称,涨跌幅) Values(?,?,?,?)"
cmd.Parameters.Clear
cmd.Parameters.Add("@日期",cs(0))
cmd.Parameters.Add("@代码",Right(cs(1),6))
cmd.Parameters.Add("@名称",cs(2))
If cs(9) = "None" Then
cmd.Parameters.Add("@涨跌幅",0)
Else
cmd.Parameters.Add("@涨跌幅",cs(9))
End If
cmd.ExecuteNonQuery
End If
End If
Next
GC.Collect '释放内存
Next
msgbox("行情数据ok!")