我正在尝试使用Microsoft.ACE.OLEDB.12.0连接到Access 2019数据库的c#程序执行下面的查询。查询工作时,我在访问中运行它。我怎样才能让它在我的程序中工作?
失败错误信息:
查询:System.Data.OleDb。OleDbException HResult=0x80040E57 Message=字段太小,无法接受您尝试添加的数据量,请尝试插入或粘贴更少的数据
INSERT INTO `PlayerAwardsMart` (`tournament`, `competition`, `place`, `award`, `player_id`, `player`, `registration_group`, `team`)
SELECT LatestActiveTournament.label AS tournament, PlayerResultsMart.Competition AS competition, PlayerResultsMart.Rank AS place, PlayerResultsMart.Award AS award, PlayerResultsMart.ID AS player_id,
PLAYER.[FIRST] + ' ' + PLAYER.[LAST] AS player, GEOCODE.CITY AS registration_group, TEAM.TEAM_NAME AS team
FROM LatestActiveTournament, ((GEOCODE INNER JOIN
(PlayerResultsMart INNER JOIN
PLAYER ON PlayerResultsMart.ID = PLAYER.ID) ON GEOCODE.GEOCODE = PLAYER.GEOCODE) INNER JOIN
TEAM ON PlayerResultsMart.TeamID = TEAM.ID)
WHERE (PlayerResultsMart.Award IS NOT NULL)
ORDER BY PlayerResultsMart.Competition, PlayerResultsMart.Rank, PlayerResultsMart.ID
连接字符串:
<add name="DataGrids.Properties.Settings.agamesConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source="C:AGAMESAGAMES.accdb";Persist Security Info=True" providerName="System.Data.OleDb"/>
我在Visual Studio 2022 v 17.5中调试了我的程序。我找到了导致异常的查询。我在实际数据库中运行了这个查询。它工作得很好。但是,我需要在我的程序中自动执行。我想我应该更认真地对待这个错误信息。这是绝对正确的。我的一个字段太小了。
Access将其截断,因此查询在那里成功。我猜Microsoft.ACE.OLEDB.12.0实际上帮了我一个忙,没有截断它。**