void Fillcombo()
{
OleDbConnection cn = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0;Data Source=Library.accdb");
OleDbCommand cmd = new OleDbCommand(@"SELECT * FROM Books", cn);
cmd.Connection = cn;
OleDbDataReader dr;
try
{
cn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
string b = dr.GetString("book");//This is the line where im getting an error
cboProgramming.Items.Add(b);
}
}
catch (Exception ex)
{
MessageBox.Show("f");
}
}
-4
A
回答
4
OleDbDataReader.GetString需要一个int
作为参数,并返回string
值。
1
// Summary:
// Gets the value of the specified column as a string.
//
// Parameters:
// ordinal:
// The zero-based column ordinal.
//
// Returns:
// The value of the specified column.
//
// Exceptions:
// System.InvalidCastException:
// The specified cast is not valid.
public override string GetString(int ordinal);
你应该传递一个int。
1
你可能想更多的东西一样:
string b = dr.GetString(dr.GetOrdinal("book"));
由于GetString()
方法(如GetInt32
和所有其他人)都将列指数 - 该指数可以与GetOrdinal
方法
+0
+1这是最完整的答案。 – DGibbs 2014-09-25 08:21:59
相关问题
- 1. System.ArgumentException:参数无效。在C#
- 2. c#参数无效
- 3. 无效参数C++ cygwin的
- 4. 在PHP中为一个有效数组获取“foreach的无效参数”
- 5. 如何在C++的main()中获得第一个参数?
- 6. 获得无效的参数脚本错误在Windows 10 IE 11
- 7. 获得一个ActionResult参数在MVC4
- 8. C#线程参数无效
- 9. C#位图 - 参数无效
- 10. C#参数无效错误
- 11. C#参数无效SQL
- 12. C#Graphics.CopyFromScreen“参数无效”
- 13. 输入了一个无效的参数:
- 14. NSExpression捕获无效参数
- 15. ucrtbase.dll:一个无效的参数传递给一个函数,该函数认为无效的参数致命
- 16. 获得一个参数上的URL
- 17. C++无效*到参数的函数
- 18. 在轨获得无效值整数()
- 19. 其中一个参数无效as3
- 20. 获得无效的参数从执行semop
- 21. 在C中,无法获得一个数组来保存新值
- 22. C++类模板是一个模板:模板参数无效
- 23. 函数无效的参数无效
- 24. C++:' - >'的无效类型参数
- 25. C linux shmget无效的参数
- 26. mersenne twister的无效参数:: seed(C++)
- 27. '*'的类型参数无效(有'双')C
- 28. 无效的参数 - c#Excel Interop Series.Points()
- 29. 为什么将一个整数值赋给C#方法参数中的一个uint参数是无效的?
- 30. 无效的参数
欢迎返回到计算器,请阅读:https://stackoverflow.com/help/how-to-ask – flayn 2014-09-25 08:13:22