以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助] 错误码  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=161315)

--  作者:sanny
--  发布时间:2021/3/12 21:32:00
--  [求助] 错误码
老师,以下黄色标注的请帮忙更正一下,另外整个代码可以优化吗 ? 感谢。


Dim txt  As  String = e.Form.Controls("TextBox1").Text
txt = Tables("生产任务单").Current("生产任务单号")
e.Form.Controls("TextBox1").Text = txt


Dim val As Integer
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "Se lect top 1 ImageBinary From {SDBC_Sa} Where BarcodeData =\'" & e.Form.Controls("TextBox1").Text & "\'and DATALENGTH(ImageBinary) > 0 and resend = 1,Date2 desc"
Dim dt As DataTable = cmd.ExecuteReader
If dt.datarows.count > 0 Then
Dim imagebytes As Byte() = dt.DataRows(0)("ImageBinary")
Dim stream As System.IO.Stream = New System.IO.MemoryStream(imagebytes)
Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(stream)
Dim pbx As WinForm.PictureBox = Forms("pic").Controls("PictureBox1")
pbx.Image = bmp

Else

cmd.CommandText = "Sel ect top 1 ImageBinary From {SDBC_Sa} Where BarcodeData =\'" & e.Form.Controls("TextBox1").Text & "\'and DATALENGTH(ImageBinary) > 0"
\'Dim dt As DataTable = cmd.ExecuteReader
If dt.datarows.count > 0 Then
Dim imagebytes As Byte() = dt.DataRows(0)("ImageBinary")
Dim stream As System.IO.Stream = New System.IO.MemoryStream(imagebytes)
Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(stream)
Dim pbx As WinForm.PictureBox = Forms("pic").Controls("PictureBox1")
pbx.Image = bmp

End If

End If

--  作者:有点蓝
--  发布时间:2021/3/13 9:42:00
--  
Dim val As Integer
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "Se lect top 1 ImageBinary From {SDBC_Sa} Where BarcodeData =\'" & e.Form.Controls("TextBox1").Text & "\'and DATALENGTH(ImageBinary) > 0 order by resend,Date2 desc"
Dim dt As DataTable = cmd.ExecuteReader
If dt.datarows.count > 0 Then
Dim imagebytes As Byte() = dt.DataRows(0)("ImageBinary")
Dim stream As System.IO.Stream = New System.IO.MemoryStream(imagebytes)
Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(stream)
Dim pbx As WinForm.PictureBox = Forms("pic").Controls("PictureBox1")
pbx.Image = bmp

End If

--  作者:sanny
--  发布时间:2021/3/13 11:43:00
--  
老师,

order by resend 加这个有点不对,我只有有钩的,resend = 1, 然后再将Date2 降序操作

--  作者:有点蓝
--  发布时间:2021/3/13 12:13:00
--  
这个是结合了1楼2条sql的结果,自己细品一下。测试有什么问题?
--  作者:sanny
--  发布时间:2021/3/13 12:31:00
--  
老师,是有点不对,

条件一 : 取 resend = 1 并且  Date2 的最晚的一条记录

条件二 :如果 没有 resend = 1 的记录, 就取Date2 最早的一条记录

--  作者:有点蓝
--  发布时间:2021/3/13 14:37:00
--  
那还是分2次把,1楼代码不变

cmd.CommandText = "Se lect top 1 ImageBinary From {SDBC_Sa} Where BarcodeData =\'" & e.Form.Controls("TextBox1").Text & "\'and DATALENGTH(ImageBinary) > 0 and resend = 1,Date2 desc"
改为
cmd.CommandText = "Se lect top 1 ImageBinary From {SDBC_Sa} Where BarcodeData =\'" & e.Form.Controls("TextBox1").Text & "\'and DATALENGTH(ImageBinary) > 0 and resend = 1 order by Date2 desc"

--  作者:sanny
--  发布时间:2021/3/13 17:56:00
--  
谢谢老师

以下这个黄色不对,可以也帮忙修改一下,谢谢。

Dim fdr As DataRow = dt.Find("BarcodeData=\'" & rr("生产任务单号") & "\' and Resend = 1,Date desc")


--  作者:有点蓝
--  发布时间:2021/3/14 20:09:00
--  
参考:http://www.foxtable.com/webhelp/topics/0396.htm