以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 如何判断返回值不存在并跳过操作? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=169225) |
-- 作者:gudao123456 -- 发布时间:2021/6/7 22:45:00 -- 如何判断返回值不存在并跳过操作? 在读取钉钉接口数据记录时,有时会遇到无效数据情况,此时,返回是空值,用空值读入数据表自然会提出引用错误提示。如何判断是为空值并跳过呢?代码如下,但不起作用,同样提示错误并终止运行,如何办?谢谢! Dim access_token As String=Functions.Execute("access_token") Dim client As DingTalk.API.IDingTalkClient = new DingTalk.API.DefaultDingTalkClient("https://oapi.dingtalk.com/user/listbypage") Dim req As DingTalk.API.Request.OapiUserListbypageRequest = new DingTalk.API.Request.OapiUserListbypageRequest() Dim rsp As DingTalk.API.Response.OapiUserListbypageResponse req.SetHttpMethod("GET") req.Offset = 0L req.Size = 50L Dim xx As String Dim jo As JObject Dim ja As JArray Dim dr As DataRow For Each dr1 As DataRow In DataTables("departmentlist").DataRows xx=dr1("department_ID") req.DepartmentId =xx rsp= client.Execute(req, access_token) jo= JObject.Parse(rsp.body) ja = jo("userlist") For i As Integer = 0 To ja.Count - 1 dr = DataTables("user_ifo").Find("user_id = \'" & ja(i)("userid").Tostring & "\'") If dr Is Nothing Then dr=DataTables("user_ifo").addnew() dr("name")=ja(i)("name").Tostring dr("user_id")=ja(i)("userid").Tostring dr("department_id")=xx dr("department_name")=dr1("department_name") If ja(i)("mobile") Is system.DBnull.value Then Continue For Else dr("mobile")=ja(i)("mobile").Tostring End If dr.save() End If Next Next |
-- 作者:有点蓝 -- 发布时间:2021/6/7 22:47:00 -- If ja(i)("mobile") Is nothing Then |
-- 作者:gudao123456 -- 发布时间:2021/6/7 23:03:00 -- 谢谢!按你说的,解决了。 再问个问题:是每次都执行 dr.save() 呢 在程序最后执行一次就够了,还是可以都不执行,到退出时提示是保存否修改 按”是”就可以了,因为存盘需要时间,如何才能有效且效率高?谢谢!
|
-- 作者:有点蓝 -- 发布时间:2021/6/7 23:04:00 -- 最后DataTables("user_ifo").save保存一下即可 |
-- 作者:gudao123456 -- 发布时间:2021/6/7 23:16:00 -- 谢谢! |