以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 请教,代码哪里出错了啊 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=159858) |
||||
-- 作者:5159518 -- 发布时间:2021/1/11 21:43:00 -- 请教,代码哪里出错了啊 Dim tb1 As Table = e.Form.Controls("Table1").Table Dim tb2 As Table = e.Form.Controls("Table2").Table Dim xb As Boolean If e.Form.Controls("ComboBox3").Text = "男" Then xb = False Else xb = True End If Dim cmd As New S QLCommand cmd.C Try cmd.BeginTransaction() \'开启事务 cmd.CommandText = "S ELECT * From {BAAB} where BAAB00 Is Null " Dim dt As DataTable = cmd.ExecuteReader(True) Dim dr As DataRow = dt.S QLFind("BAAB00 Is Null","[_Identify]") If dr Is Nothing Then dr = dt.AddNew End If dr("BAAB00") = Functions.Execute("X00序列号生成器_带前缀","BAAB","BAAB00","BAAB") dr("BAAB01") = e.Form.Controls("DateTimePicker1").Text dr("BAAB02") = e.Form.Controls("ComboBox2").Text dr("BAAB03") = e.Form.Controls("ComboBox1").Text dr("BAAB04") = e.Form.Controls("TextBox1").Text dr("BAAB05") = xb dr("BAAB06") = e.Form.Controls("NumericComboBox1").Text dr("BAAB07") = e.Form.Controls("ComboBox4").Text dr("BAAB08") = Functions.Execute("X00序列号生成器_带前缀","BAAB","BAAB08","BAAB") dr("BAAB09") = e.Form.Controls("TextBox2").Text dr("BAAB10") = Functions.Execute("X00序列号生成器_带前缀","BAAB","BAAB10","BAAB") dr("BAAB11") = e.Form.Controls("TextBox3").Text dr.Save() Dim lm As String = dr("BAAB00") Dim lx As String = dr("BAAB08") Dim wj As String = dr("BAAB10") cmd.CommandText = "S ELECT * From {ACAB} where ACAB01 = \'" & lx & "\'" Dim dt1 As DataTable = cmd.ExecuteReader(True) Dim dr1 As DataRow For Each dr1 In dt1.DataRows Dim tr As DataRow = tb1.DataTable.Find("_Identify = \'" & dr1("_Identify") & "\'") If tr Is Nothing Then dr1("ACAB00") = Nothing dr1("ACAB01") = Nothing dr1("ACAB02") = Nothing dr1("ACAB03") = Nothing dr1("ACAB04") = Nothing dr1.Save() End If Next For Each tr As DataRow In tb1.DataTable.DataRows If tr.IsNull("ACAB00") = False Then dr1 = dt1.S QLFind("[_Identify] = \'" & tr("_Identify") & "\'") If dr1 Is Nothing Then dr1 = dt1.S QLFind("ACAB00 Is Null") If dr1 Is Nothing Then dr1 = dt1.AddNew End If dr1("ACAB00") = Functions.Execute("X00序列号生成器_带前缀","ACAB","ACAB00","ACAB") dr1("ACAB01") = lx dr1("ACAB02") = tr("ACAB02") dr1("ACAB03") = tr("ACAB03") dr1("ACAB04") = "投递简历" dr1.Save() End If End If Next cmd.CommandText = "SE LECT * From {ADAC} where [_Identify] is null" Dim dt2 As DataTable = cmd.ExecuteReader(True) \'生产datatable表,并传递给"dt"表 Dim dr2 As DataRow cmd.CommandText = "SE LECT * From {ADAD} where [_Identify] is null" Dim dt3 As DataTable = cmd.ExecuteReader(True) \'生产datatable表,并传递给"dt"表 Dim dr3 As DataRow For Each tr As DataRow In tb2.DataTable.DataRows Dim fl As String = tr("ADAC04") \'定义传递参数(含路径文件名) dr2 = dt2.S QLFind("ADAC00 IS NULL","_Identify") If dr2 Is Nothing Then dr2 = dt2.AddNew End If dr2("ADAC00") = Functions.Execute("X01序列号生成器_简略版","ADAC") \'ID赋值 dr2("ADAC01") = wj \'文件ID赋值 dr2("ADAC03") = FileSys.GetName(fl) \'文件名赋值 dr2("ADAC04") = FileSys.GetName(fl) \'显示名赋值 Dim t2 As Integer = 0 \'定义序列号累计数值 If FileSys.FileExists(fl) Then dr3 = dt3.S QLFind("ADAD02 = \'" & CRCCheckFile(fl) & "\'") \'查找相同文件的行 If dr3 Is Nothing \'如果没有相同文件的行 dr3 = dt3.SQ LFind("ADAD00 Is Null") If dr3 Is Nothing dr3 = dt3.AddNew \'加一行 End If dr3("ADAD00") = Functions.Execute("X01序列号生成器_简略版","ADAD") \'ID赋值 End If dr2("ADAC02") = dr3("ADAC00") \'附件ID赋值 Else MessageBox.Show("文件不存在或路径/文件名错误,请核对后再添加!") \'cmd.Rollback() \'则回滚事务 End If dr2.Save() dr3("ADAD01") = fl.SubString(fl.LastIndexOf(".") + 1) \'提取文件扩展名并赋值给扩展名 dr3("ADAD02") = CRCCheckFile(fl) \'CRC赋值 dr3.Save() dr3.S QLInsertFile("ADAD03",fl) \'插入文件 dr3.Save() \'If bz1 = False AndAlso dt.HasChanges Then \'MessageBox.Show("保存失败,请于管理员联系!","保存失败!") \'cmd.Rollback() \'则回滚事务 \'Else If dt1.HasChanges OrElse dt2.HasChanges Then \'如果任何一个表保存失败 \'MessageBox.Show("保存失败,请于管理员联系!","保存失败!") \'cmd.Rollback() \'则回滚事务 \'End If Next cmd.Commit() \'提交事务 \'e.Form.Close() Catch ex As Exception \'如果出错 cmd.Rollback() \'则回滚事务 MessageBox.Show(ex.Message, "错误",MessageBoxButtons.OK,MessageBoxIcon.Error) End Try 一旦运行就报错 然后重启项目,删除bin文件夹,又可以用了,但是一会又报错了 然后又多了一个报错: .NET Framework 版本:4.0.30319.42000 Foxtable 版本:2020.5.29.8 错误所在事件:窗口,010002 简历登记,Button2,Click 详细错误信息: 此 OleDbTransaction 已完成;它再也无法使用。 [此贴子已经被作者于2021/1/11 21:51:09编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2021/1/11 22:05:00 -- 估计是二进制列的问题,试试使用sql插入或者更新二进制数据 Dim cmd As new SQLCommand cmd.C cmd.CommandText = "Insert Into test (图片) Values(?)" Dim ImageByte() As Byte = System.IO.File.ReadAllBytes("D:\\test.JPG") \'读取文件流,并将读到的二进制数据放入数组ImageByte中, cmd.Parameters.Add("@图片", ImageByte) cmd.ExecuteNonQuery cmd.Com mandText = "up date {web上传图片} set 图片= ? where 姓名=?" Dim ImageByte() As Byte = System.IO.File.ReadAllBytes(wj) \'读取文件流,并将读到的二进制数据放入数组ImageByte中, cmd.Parameters.Add("@图片", ImageByte) cmd.Parameters.Add("@姓名", dr("姓名")) cmd.ExecuteNonQuery |
||||
-- 作者:5159518 -- 发布时间:2021/1/16 11:27:00 -- 还是不行,报错啊 .NET Framework 版本:4.0.30319.42000 Foxtable 版本:2020.5.29.8 错误所在事件:自定义函数,F05批量添加附件 详细错误信息: 调用的目标发生了异常。 已添加了具有相同键的项。 下面是自定义函数的代码:
在添加第一个附件的时候,是可以的,但是第二个文件就报错了 |
||||
-- 作者:有点蓝 -- 发布时间:2021/1/16 14:11:00 -- If cmd.ExecuteScalar() Is Nothing Then \'如果没有相同文件的行 MessageBox.Show(fjid) cmd.CommandText = "Select top 1 [_Identify] From {ADAD} Where ADAD00 Is Null Order by [_Identify]" Dim id2 As Integer = cmd.ExecuteScalar() If cmd.ExecuteScalar() Is Nothing Then cmd.CommandText = "Insert Into ADAD(ADAD00,ADAD01,ADAD02,ADAD03) Values(\'" & fjid & "\',\'" & kz & "\',\'" & crc & "\',?)" cmd.Parameters.clear cmd.Parameters.Add("@ADAD03", wj) cmd.ExecuteNonQuery Else \'cmd.CommandText = "Select top 1 [_Identify] From {ADAD} Where ADAD00 Is Null Order by [_Identify]" \'Dim ide As Integer = cmd.ExecuteScalar() MessageBox.Show("自增长序列:" & id2) \'cmd.CommandText = "update {ADAD} set ADAD00 = \'" & fjid & "\',ADAD01 = \'" & kz & "\',ADAD02 = \'" & crc & "\',ADAD03 = ? where [_Identify] = \'" & id2 & "\'" MessageBox.Show(wj.Length) cmd.CommandText = "update {ADAD} set ADAD00 = ?,ADAD01 = ?,ADAD02 = ?,ADAD03 = ? where [_Identify] = ?" cmd.Parameters.clear cmd.Parameters.Add("@ADAD00", fjid) cmd.Parameters.Add("@ADAD01", kz) cmd.Parameters.Add("@ADAD02", crc) cmd.Parameters.Add("@ADAD03", wj) cmd.Parameters.Add("@[_Identify]", id2) cmd.ExecuteNonQuery End If End If End If
|