因此,每当我尝试将信息添加到MS访问数据库时,我都会收到以下错误:行/列没有数据。我查看了我的代码并尝试搜索类似的问题,有没有人在我的代码中看到一个闪闪发光的缺陷,可以解释为什么我会收到此错误?任何帮助将不胜感激。提前致谢。
try
{
conn.Open();
String selectTeamName_KickballTeams = "select season, divisionLocation, teamName from kickballTeams";
OleDbCommand cmd2 = new OleDbCommand(selectTeamName_KickballTeams, conn);
OleDbDataReader reader = cmd2.ExecuteReader();
int seasonOrdinal = reader.GetOrdinal("season");
int teamDivisionOrdinal = reader.GetOrdinal("divisionLocation");
int teamNameOrdinal = reader.GetOrdinal("teamName");
String my_query = null;
OleDbCommand cmd = new OleDbCommand(my_query, conn);
int count = reader.FieldCount;
//int i = 0;
String teamName1 = null;
String teamSeason2 = null;
String teamDivision2 = null;
String teamName2 = null;
while (reader.Read())
{
teamSeason1 = reader.GetString(seasonOrdinal);
teamDivision1 = reader.GetString(teamDivisionOrdinal);
teamName1 = reader.GetString(teamNameOrdinal);
//Hippos
reader.NextResult();
teamSeason2 = reader.GetString(seasonOrdinal);
//season = Winter
teamDivision2 = reader.GetString(teamDivisionOrdinal);
//teamDivision = South County Sundays
if (teamSeason1.Equals(teamSeason2) && teamDivision1.Equals(teamDivision2))
{
teamName2 = reader.GetString(teamNameOrdinal);
//Rhinos
my_query = "INSERT INTO fullSchedule(season,divisionLocation,fieldNumber,gameTime,gameDate,teamName,teamName2)VALUES('" + teamSeason1 + "','" + teamDivision1 + "','" + fieldNumber + "','"
+ firstGameTime + "','" + divisionDate + "','" + teamName1 + "','" + teamName2 + "')";
cmd.ExecuteNonQuery();
}
else
{
}
reader.NextResult();
teamName1 = teamName2 = null;
}
reader.Close();
}
catch (Exception ex)
{
MessageBox.Show("Failed due to" + ex.Message);
}
finally
{
conn.Close();
}
}