以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]读取服务器数据 报500错误 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=153836) |
-- 作者:天一生水 -- 发布时间:2020/8/25 8:34:00 -- [求助]读取服务器数据 报500错误 蓝老师好! 最近在读取股票行情数据时经常报错,不知道是什么原因,前几个月没有出现这种情况。是读取太快?还是服务器不稳定?还是下面的代码有问题?或者如果要捕获错误,跳过错误,怎么修改代码? 请老师指教。 谢谢! 代码: \'\'\' Dim s As String = e.Form.Controls("CheckedComboBox指定股票").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!") |
-- 作者:有点蓝 -- 发布时间:2020/8/25 8:42:00 -- 500是网站的问题,https://www.baidu.com/baidu?word=http+500 |