|
我已经用Google在搜索了这个错误之后,我还没有得出我为什么会收到这个错误的结论。我试图用一些数据填充DataGridView。这是我的代码。
* v9 ], {! G$ @$ A) nPrivate Sub LoadGrid() Dim cmd As New OleDbCommand Dim dt As DataTable With cmd .CommandText = "project_master_query" .CommandType = CommandType.StoredProcedure .Connection = New OleDbConnection(My.Settings.cnnString) End With dt = GetData(cmd) dgvData.DataSource = dtEnd SubPrivate Function GetData(ByVal cmd As OleDbCommand) As DataTable Dim dt As New DataTable Using cmd.Connection cmd.Connection.Open() dt.Load(cmd.ExecuteReader(CommandBehavior.CloseConnection)) End Using Return dtEnd Function查询存储在Access中的“ project_master_query”。
6 i- o! T1 e! n h+ m8 M: Q9 V+ X; } SELECT project_master.*,location_master.LocationName, project_currentmilestonedef.MilestoneDefID, project_currentmilestonedef.MilestoneName,project_regions.RegionName, owner_fullname.FullName AS OwnerFullName,designer_fullname.FullName AS DesignerFullName, project_issuecount.HasOpenIssues,project_updated_closedate.UpdatedCloseDate, project_bonusdays.BonusDays,project_bonusdays.IsGreen,project_bonusdays.IsYellow, project_bonusdays.IsRed,checklist_days_perproject_defined_1.Week1, checklist_days_perproject_defined_1.Week2,checklist_days_perproject_defined_1.Week3, checklist_days_perproject_defined_1.Week4,project_issueduration.ProjectIssueDurationDays, project_active_status.ProjectIsOpen,project_requirement_status.RequirementStatusName, priority_def.PriorityShortName FROM project_requirement_status RIGHT JOIN (project_regions RIGHT JOIN (priority_def RIGHT JOIN (location_master RIGHT JOIN ((((checklist_days_perproject_defined AS checklist_days_perproject_defined_1 RIGHT JOIN ((((((((contacts_fullname AS designer_fullname RIGHT JOIN (contacts_fullname AS owner_fullname RIGHT JOIN project_master ON owner_fullname.ContactID = project_master.ContactOwner) ON designer_fullname.ContactID = project_master.ContactDesigner) LEFT JOIN project_issuecount ON project_master.ProjectID = project_issuecount.ProjectID) LEFT JOIN project_currentmilestonedef ON project_master.ProjectID = project_currentmilestonedef.ProjectID) LEFT JOIN project_within_benchmark_week1 ON project_master.ProjectID = project_within_benchmark_week1.ProjectID) LEFT JOIN project_within_benchmark_week2 ON project_master.ProjectID = project_within_benchmark_week2.ProjectID) LEFT JOIN project_within_benchmark_week3 ON project_master.ProjectID = project_within_benchmark_week3.ProjectID) LEFT JOIN project_updated_closedate ON project_master.ProjectID = project_updated_closedate.ProjectID) LEFT JOIN checklist_days_perproject_defined ON project_master.ProjectID = checklist_days_perproject_defined.ProjectID) ON checklist_days_perproject_defined_1.ProjectID = project_master.ProjectID) LEFT JOIN project_issueduration ON project_master.ProjectID = project_issueduration.ProjectID) LEFT JOIN project_active_status ON project_master.ProjectID = project_active_status.ProjectID) LEFT JOIN project_bonusdays ON project_master.ProjectID = project_bonusdays.ProjectID) ON location_master.LocationID = project_master.Location) ON priority_def.PriorityDefID = project_master.ProjectPriority) ON project_regions.RegionID = project_master.Region) ON project_requirement_status.RequirementStatusID = project_master.RequirementStatus;如你所见,查询中根本没有Nz,所以我不明白为什么会这样。一旦调用dt.Load,这个错误就会发生。) e: o* E9 z) c
& b o! N$ O- ?. W 解决方案: ) v9 m* _% \; B
该Nz在许多连接之一中引用的视图/查询中,函数最有可能。您必须仔细阅读所有这些内容。
4 L6 _! F4 {+ I: x$ i由于Nz()是Access应用程序(而不是Access因此,当您尝试从驱动程序)的功能时Access当应用程序外部使用时,它将失败。您可以替换它Nz与IIf(IsNull()结构。
9 n9 ~2 v5 [1 _" Z请参阅IIf和的文档IsNull5 k0 g0 v$ Q" C
放在一起:
9 v' e1 d( V% @: y% M8 BNz(expr,[valueifnull])
+ {0 D3 h0 U! n( v变成3 Q( L% `5 J& ?
IIf(IsNull(expr),valueifnull,valueifnotnull): Z- U$ V7 s+ M# R2 O ~
例子
6 d" Z# _' f/ o' R( E8 G( N. z: G默认: Nz(tbl.A) => IIf(IsNull(tbl.A),'',tbl.A)
6 E. O- }! J' G) w后备功能: Nz(tbl.A,tbl.B) => IIf(IsNull(tbl.A),tbl.B,tbl.A) |
|