确实可以,我前面不行是case后面只加了一个“商品简名”其他没加!
------下面将我臃肿的代码发上来,以后研究!
Dim dr As DataRow = e.DataRow
Dim dt As DataTable
Select Case e.DataCol.name '判断发生数据更改的列列名是不是我们要的列名
Case "商品简名" '如果列名是"商品简名"则执行下面的语句
If e.NewValue Is Nothing Then '如果新录入的数据为空
e.DataRow("商品全名") = Nothing '则对应行的商品拼音码录入空值
Else '如果有录入,则执行下面的代码
If dr.IsNull("属性") Then
If dr.IsNull("型号") Then
If dr.IsNull("品牌商标") Then
e.DataRow("商品全名") = dr("商品简名")
Else
e.DataRow("商品全名") = (dr("品牌商标") & dr("商品简名"))
End If
Else
If dr.IsNull("属性") Then
If dr.IsNull("品牌商标") Then
e.DataRow("商品全名") = (dr("型号") & dr("商品简名"))
Else
e.DataRow("商品全名") = (dr("品牌商标") & dr("型号") & dr("商品简名")) '则如果品牌,商品?自定义分类全部有数据
End If
Else
If dr.IsNull("品牌商标") Then
e.DataRow("商品全名") = (dr("属性") & dr("型号") & dr("商品简名"))
Else
e.DataRow("商品全名") = (dr("品牌商标") & dr("属性") & dr("型号") & dr("商品简名")) '则如果品牌,商品?自定义分类全部有数据
End If
End If
End If
Else
If dr.IsNull("型号") Then
If dr.IsNull("品牌商标") Then
e.DataRow("商品全名") =(dr("属性") & dr("商品简名"))
Else
e.DataRow("商品全名") = (dr("品牌商标") & dr("属性") & dr("商品简名"))
End If
Else
If dr.IsNull("品牌商标") Then
e.DataRow("商品全名") = (dr("属性") & dr("型号") & dr("商品简名"))
Else
e.DataRow("商品全名") = (dr("品牌商标") & dr("属性") & dr("型号") & dr("商品简名")) '则如果品牌,商品?自定义分类全部有数据
End If
End If
End If
End If
Case "商品全名" '如果列名是"商品全名"则执行下面的语句
If e.NewValue Is Nothing Then '如果新录入的数据为空
e.DataRow("商品拼音码") = Nothing '则对应行的商品拼音码录入空值
Else '如果有录入,则执行下面的代码
e.DataRow("商品拼音码") = getpinyin(e.NewValue ,1) '将信录入的内容以拼音码的的形式录入商品拼音码
End If
Case "品牌商标" , "属性" ,"型号"
dt = dr.DataTable
dt.DataCols("商品简名").RaiseDataColChanged()
End Select
--------以下是老师指点以后我修改过的代码,测试时可行的!
Dim dr As DataRow = e.DataRow
Select Case e.DataCol.name '判断发生数据更改的列列名是不是我们要的列名
Case "商品简名", "品牌商标", "属性", "型号"
e.DataRow("商品全名") = dr("品牌商标") & dr("属性") & dr("型号") & dr("商品简名")
'则如果品牌,商品?自定义分类全部有数据
Case "商品全名" '如果列名是"商品全名"则执行下面的语句
If e.NewValue = Nothing Then '如果新录入的数据为空
e.DataRow("商品拼音码") = Nothing '则对应行的商品拼音码录入空值
Else '如果有录入,则执行下面的代码
e.DataRow("商品拼音码") = getpinyin(e.NewValue ,1) '将信录入的内容以拼音码的的形式录入商品拼音码
End If
End Select