If e.DataCol.Name = "员工姓名" Then
If e.DataRow.IsNull("员工姓名") Then
e.DataRow("工号") = Nothing
Else
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "SELECT * From {销售人员档案}"
dt = cmd.ExecuteReader()
If dt.Datarows.Count > 0 Then
e.DataRow("工号") = Format(dt.Compute("Max(工号)") + 1,"000")
Else
e.DataRow("工号") = "HG" & "001"
End If
End If
End If
这个带有字符的编号,一直提示字符不能转换成DOUBLE数据不成功,我用转换字符的函数也不行
感觉你这段代码很不严谨
1、先是判断后台是否有数据,后面又从已经加载的表中取编号的最大值,不有些矛盾吗?
2、至于出错,是因为你的工号列是个字符型,内容时"HG001"、"HG002",这样的内容怎么能和1相加呢?
[此贴子已经被作者于2011-9-20 17:29:05编辑过]
我的判断是看后台工号列有没有数据,如果有在工号列的数据上加上1,没有的话就是HG001,关键就是HG001就是带有字符不能增加,我转换了也不行?你帮我看看这个HG增加我怎么写代码?
如果你是根据已经加载的表取最大编号,何必从后台判断是否有数据呢?
直接:
if datatables("某表").Datarows.count > 0 Then
end if
不就行了吗?
至于相加问题,这样解决:
Dim s As String = dt.Compute("Max(工号)")
Dim v As Integer = s.SubString(2)
e.DataRow("工号") = Format(v + 1,"000")
我是不想加载数据而增加行时编号增加1,代码:
If e.DataCol.Name = "员工姓名" Then
If e.DataRow.IsNull("员工姓名") Then
e.DataRow("工号") = Nothing
Else
Dim cmd1 As New SQLCommand
Dim dt1 As DataTable
Dim dr As DataRow
cmd1.C
cmd1.CommandText = "SELECT * From {单号定义}"
dt1 = cmd1.ExecuteReader()
dr = dt1.find("表名='" & CurrentTable.Name & "'")
If dr IsNot Nothing Then
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "SELECT * From {销售人员档案}"
dt = cmd.ExecuteReader()
If dt.Datarows.Count>0 Then
Dim s As String = dt.Compute("Max(工号)")
Dim v As Integer = s.SubString(2)
e.DataRow("工号") = Format(v + 1,"000")
Else
e.DataRow("工号") = dr("单号定义") & "001"
End If
End If
End If
End If
帮忙看看!