因为它为我节省了大量的代码! 用5代替70行代码。 示例: ===开始冗长的代码(70行)=== 选择案例sTableName 案例" lkp01RefSource" da01RefSource.Fill(DsSelectionList1," lkp01RefSource") DgMasterLists.SetDataBinding(DsSelectionList1," lkp01RefSource") Case" lkp02GrpCategory" da02GrpCategory.Fill(DsSelectionList1," lkp02GrpCategory") DgMasterLists.SetDataBinding(DsSelectionList1," lkp02GrpCategory") Case" lkp03PrgmObjective" ; da03PrgmObjective.Fill(DsSelectionList1," lkp03PrgmObjective") DgMasterLists.SetDataBinding(DsSelectionList1,&quo t; lkp03PrgmObjective") Case" lkp06JobTitle" da06JobTitle.Fill(DsSelectionList1," lkp06JobTitle") DgMasterLists.SetDataBinding(DsSelectionList1 ,lkp06JobTitle) Case" lkp07Qualification" da07Qualification.Fill(DsSelectionList1," lkp07Qualification") DgMasterLists.SetDataBinding( DsSelectionList1,lkp07Qualification) Case" lkp08DayOfWeek" da08DayOfWeek.Fill(DsSelectionList1," lkp08DayOfWeek") DgMasterLists.SetDataBinding (DsSelectionList1,lkp08DayOfWeek) Case" lkp09MealType" DgMasterLists。 SetDataBinding(DsSelectionList1," lkp09MealType") Case" lkp10MerchandType" da10MerchandType.Fill(DsSelectionList1," lkp10MerchandType") DgMas terLists.SetDataBinding(DsSelectionList1," lkp10MerchandType") Case" lkp11CommResource" da11CommResource.Fill(DsSelectionList1," lkp11CommResource") DgMasterLists.SetDataBinding(DsSelectionList1," lkp11CommResource") Case" lkp12TelephonyDevice" da12TelephonyDevice.Fill(DsSelectionList1," lkp12TelephonyDevice") DgMasterLists.SetDataBinding(DsSelectionList1, " lkp12TelephonyDevice") Case" lkp13WwwType" da13WwwType.Fill(DsSelectionList1," lkp13WwwType") DgMasterLists.SetDataBinding(DsSelectionList1," lkp13WwwType") Case" lkp14ModeOfContact" da14ModeOfContact.Fill(DsSelectionList1," ; lkp14ModeOfContact") DgMasterLists.SetDataBinding(DsSelectionList1," lkp14ModeOfContact") Case" lkp15MsgTopic" da15MsgTopic.Fill(DsSelectionList1," lkp15MsgTopic") DgMasterLists.SetDataBinding(DsSelectionList1," lkp15MsgTopic") 案例" lkp16ScheduleType" da16ScheduleType.Fill(DsSelectionList1," lkp16ScheduleType") DgMasterLists.SetDataBinding(DsSelectionList1," lkp16ScheduleType") Case" lkp17WeightGroup" da17WeightGroup.Fill(DsSelectionList1," lkp17WeightGroup") DgMasterLists.SetDataBinding(DsSelectionList1," lkp17WeightGroup") Case" lkp18ProgramCategory" da18ProgramCategory.Fill(DsSelectionList1," lkp18ProgramCategory") DgMasterLists.SetDataBinding(DsSelectionList1, " lkp18ProgramCategory") 案例" lkp19Element" da19Element.Fill(DsSelectionList1," lkp19Element") DgMasterLists.SetDataBinding(DsSelectionList1," lkp1 9Element") Case" enm1FoodAllergy" daFoodAllergy.Fill(DsSelectionList1," enm1FoodAllergy") DgMasterLists.SetDataBinding(DsSelectionList1," ; enm1FoodAllergy") Case" enm2EnvironAllergy" DgMasterLists.SetDataBinding(DsSelectionList1, enm2EnvironAllergy) Case" enm3MedicalAllergy" daMedicalAllergy.Fill(DsSelectionList1," enm3MedicalAllergy") DgMasterLists.SetDataBinding(DsSelectionList1 ,enm3MedicalAllergy) Case" enm4MedConcern" daMedConcern.Fill(DsSelectionList1," enm4MedConcern") DgMasterLists.SetDataBinding( DsSelectionList1,enm4MedConcern) Case" enm5ActivityRequest" daActivityRequest.Fill(DsSelectionList1," enm5ActivityRequest") DgMasterLists.SetDataBinding(DsSelectionList1," enm5ActivityRequest") Case Else TableErrorMessage() 结束选择 ===冗长的代码结束=== ===开始短代码(5行)===== Dim strDa As String strDa = strTbl.Remove(0,5) strDa = strDa.Insert(0, da) CType(strDa,SqlDataAdapter).fill(DsMasterLists1,strTbl) DgMasterLists.SetDataBinding(DsMasterLists1,strTbl) ===短代码结束=== (还有其他优点) 返回我的原始问题: 代码在调试模式下工作。 exe工作。 有没有人预料到我有任何 部署之后的问题? 有没有人建议任何其他alturnatives? 有没有人建议一种方法来阻止恼人的构建错误? 比k你, --Doug " Scott M." < S - *** @ nospam.nospam>在消息新闻中写道:< u5 ************** @ TK2MSFTNGP12.phx.gbl> ... I am using the following code instead of a very lengthly select casestatement. (I have a lot of lookup tables in a settings form that are selectedfrom a ListBox. The data adapters are given a similar name to thetable. Rather than making a long Select Case that could becomeobsolete if lookup tables are added and the source table of theListBox is edited I came up with this code.) This code works but of course it gives me build errors. Error:[Value of type ''String'' cannot be converted to''System.Data.SqlClient.SqlDataAdapter''.] === code snippit ===Private Sub lstMasterLists_Click(ByVal sender As Object, _ByVal e As System.EventArgs) Handles lstMasterLists.Click ''To populate the dgMasterLists with the proper table''1. use the returned TableName to make the DataAdapter name''2. Convert the string to the DataAdampter type ''Get the TableName from the selected item in the list boxDim strTbl As StringstrTbl = Me.lstMasterLists.SelectedItem.ToString ''Make the DataAdapter name from the table nameDim strDa As StringstrDa = strTbl.Remove(0, 5)strDa = strDa.Insert(0, "Da") CType(strDa, SqlDataAdapter).fill(DsMasterLists1, strTbl)DgMasterLists.SetDataBinding(DsMasterLists1, strTbl) End Sub====== The code works in debug mode.The exe works. Does anyone anticipate me having any problems with this afterdeployment?Does anyone suggest any other alturnatives?Does anyone suggest a way to stop the annoying build errors? 解决方案 这篇关于CType和恼人的构建错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-25 09:04