c# - 填充数据适配器时字典中不存在给定的键
问题描述
字典中不存在给定的键。
说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.Collections.Generic.KeyNotFoundException:字典中不存在给定的键。
MySqlConnection con = new MySqlConnection("Data Source=localhost; Database=gransells; User ID=root; Password=PASSWORD;");
MySqlCommand cmd = new MySqlCommand("select description from product where productId=1", con);
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
解决方案
您在正在设置但未检索的表中有主键。在 select 语句中使用该主键。
推荐阅读
- r - 如何通过 R 中的 dplyr 逐行选择 tibble 中的随机元素?
- java - Unicode ICU 而不是 java.time.DateTimeFormatter 应该用于国际日期和时间
- javascript - React 不更新状态的问题(钩子)
- php - TypeError: 传递给 PHPUnit\Framework\Assert::assertFileExists() 的参数 1 必须是字符串类型,给定 null,
- c - C编程练习
- here-api - 这里API批量距离计算
- html - 引导轮播不滚动错误
- python - 使用 seaborn 和 matplotlib.pyplot 在 python 中处理 Xticks
- r - R highcharts 图表上的特定颜色列
- firebase - 搜索功能流重构