以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 移动开发中,怎么实现不加载表,直接用SQL语句实现数据的更新与插入? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=137852) |
-- 作者:李孝春 -- 发布时间:2019/7/17 10:38:00 -- 移动开发中,怎么实现不加载表,直接用SQL语句实现数据的更新与插入? 移动开发中,怎么实现不加载表,直接用SQL语句实现数据的更新与插入? 红色部分代码dr定义相关的内容,如何用SQL语句进行实现呢? 页面代码如下: Dim e As RequestEventArgs = args(0) \'定义故障报修表 Dim drgz As DataTable Dim cmdgz As New SQLCommand cmdgz.C cmdgz.CommandText = "Sel ect * from {故障报修}" drgz=cmdgz.ExecuteReader \'定义故障处理表 Dim drgzcl As DataTable Dim cmdgzcl As New SQLCommand cmdgzcl.C cmdgzcl.CommandText = "Sel ect * from {故障处理}" drgzcl=cmdgzcl.ExecuteReader drgzcl.DataCols("处理提交时间").SetDateTimeFormat(DateTimeFormatEnum.DateLongTime) Dim wb As New weui Select Case e.Path Case "baoxiuchuli.htm" If e.PostValues.Count = 0 Then wb.AddPageTitle("","ph1","【报修处理】录入") wb.AddForm("","form1","baoxiuchuli.htm") With wb.AddInputGroup("form1","ipg1","报修处理") .AddInput("处理时间","处理时间","date") .AddInput("报修提交时间","报修提交时间","text") With wb.AddInputGroup("form1","ipg44","报修情况说明") .AddTextArea("报修摘要",5).Placeholder = "" End With With wb.AddInputGroup("form1","ipg55","处理内容及处理说明") .AddTextArea("处理内容",5).Placeholder = "请填写故障处理的具体内容 " .AddSelect("处理结果","处理结果","|处理完毕|有待进一步处理|等待反馈结果") End With With wb.AddInputGroup("form1","ipg66","处理人员") With .AddSelect("处理人员","处理人员","|" & drgz.sqlGetComboListString("处理人员","是否处理=\'false\'")) End With .AddInput("运维人员","运维人员","text") End With End With With wb.AddButtonGroup("form1","btg1",True) .Add("btn1", "确定", "submit") End With wb.AppendHTML("<script src=\'./lib/ajaxformbaoxiu.js\'></script>") \'引入脚本文件 e.WriteString(wb.Build) Else Dim nms2 = New String() {"rdg1"} Dim nms() As String = {"处理时间","报修编号","报修人员","报修摘要","处理内容","处理结果","处理人员"} \'不能为空的列名数组 For Each nm As String In nms If e.PostValues.ContainsKey(nm) = False Then \'生成错误提示页 With wb.AddMsgPage("","msgpage","增加失败", nm & "列不能为空!") .icon = "Warn" \'改变图标 .AddButton("btn1","返回").Attribute = "" End With e.WriteString(wb.Build) Return "" \' \'必须返回 End If Next nms = New String() {"处理编号","处理时间","报修时间","报修编号","报修内容","报修故障","报修人员","报修摘要","处理内容","处理结果","处理人员","运维人员","处理耗时","处理摘要","处理提交时间","报修提交时间"} \'重新定义了nms数组,增加了两列. Dim dr As DataRow = DataTables("故障处理").AddNew() For Each nm As String In nms If e.PostValues.ContainsKey(nm) Then dr(nm) = e.PostValues(nm) \' cmdgzcl.CommandText = "insert into drgzcl(nm) values(e.PostValues(nm)) " \' cmdgzcl.ExecuteNonQuery End If Next For Each nm As String In nms2 If e.PostValues.ContainsKey(nm) Then dr(e.PostValues(nm)) = True End If Next \'获取sql服务器时间,并写入处理提交时间列 Dim cmd As New SQLCommand Dim dt As Date cmd.C \'cmd.CommandText = "Sel ect GetDate()" cmd.CommandText = "Sel ect CONVERT(varchar(100), GETDATE(), 20)" dt = cmd.ExecuteScalar() dr("处理提交时间")=dt \'根据处理时间生成处理编号 If dr.IsNull("处理时间") Then dr("处理编号") = Nothing Else Dim bh As String = Format(dr("处理时间"),"yyyyMMdd") \'取得报修编号的8位前缀 If dr("处理编号").StartsWith(bh) = False \'如果报修编号的前8位不符 Dim max As String Dim idx As Integer max = drgzcl.sqlCompute("Max(处理编号)","处理时间 = " & dr("处理时间") & " And [_Identify] <> " & dr("_Identify")) \'取得该天的最大报修编号 If max > "" Then \'如果存在最大报修编号 idx = CInt(max.Substring(9,3)) + 1 \'获得最大报修编号的后三位顺序号,并加1 Else idx = 1 \'否则顺序号等于1 End If dr("处理编号") = bh & "-" & Format(idx,"000") End If End If \' \'保存并生成增加成功提示页面 dr("处理摘要")= "[" & dr("报修人员") & "]同志于[" & dr("报修时间") & "]提出编号为[" & dr("报修编号") & "]的故障报修,经[" & dr("处理人员") & "][" & dr("运维人员") & "]于[" & dr("处理时间") & "]采取[" & dr("处理内容") & "]后,[" & dr("处理结果") & "].请及时使用,若有疑问请报修." If dr.IsNull("报修提交时间") Or dr.IsNull("处理提交时间") Then dr("处理耗时") = Nothing \'MessageBox.Show("处理耗时因值不足暂时不计算") Else \'MessageBox.Show("处理耗时计算") Dim tp As TimeSpan tp = dr("处理提交时间") - dr("报修提交时间") dr("处理耗时") = tp.TotalSeconds() \'真正的时段型数据要转换为秒数,才能存入时段列 End If dr.save() \'更新故障报修表中的是否处理字段为true Dim cmd1 As New SQLCommand cmd1.C cmd1.CommandText = "up date 故障报修 set 是否处理=\'true\' where 报修编号=\'" & e.values("报修编号") & "\' " cmd1.ExecuteNonQuery() \'添加成功后的页面提示 With wb.AddMsgPage("","msgpage","增加成功", "好好学习,天天向上") \'生成成功提示页 .AddButton("btn1","继续增加","baoxiuchuli.htm") .AddButton("btn2","返回首页","index.htm") End With End If e.WriteString(wb.Build) End Select
|
-- 作者:有点蓝 -- 发布时间:2019/7/17 10:44:00 -- 1、drgzcl=cmdgzcl.ExecuteReader(true) 2、Dim dr As DataRow = drgzcl.AddNew()
|