这两个代码,写在:表事件,DataColChanged 中,但作用感觉不一样。不清楚哪个时候用在哪里对的?具体区别有哪里?应该怎样准确地使用?
给我感觉就是:SELECT这个方法,在RaiseDataColChanged时,好像用的是旧值,不是新值;但是,如果用datatable 的find 方法,会不会出现数据未加载,找不到表,的情况呢?(我用的是外部数据库,ACCSEE)
If e.DataCol.Name = "客户编号" Then
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
Dim dr As DataRow = e.DataRow
cmd.CommandText = "SELECT * Fro m {客户} Where [客户编号] = '" & dr("客户编号") & "'"
dt = cmd.ExecuteReader
If dt.DataRows.Count > 0 Then
dr("发包单位") = dt.DataRows(0)("公司名称")
End If
End If
If e.DataCol.Name = "客户编号" Then
Dim dr As DataRow = DataTables("客户").Find("客户编号 = '" & e.DataRow("客户编号") & "'")
If dr IsNot Nothing Then
e.DataRow("发包单位") = dr("公司名称")
End If
End If