c# - DataTable 列数据到组合框错误

标签 c# mysql winforms combobox

我想在组合框中显示数据表列中的所有数据。该表格用于订购新库存并保存到数据库中。

我遵循了本教程 http://youtu.be/cdkDHkXyVFI
我收到 2 条错误消息:

Error   1   The best overloaded method match for 'System.Data.Common.DbDataReader.GetString(int)' has some invalid arguments  
Error   2   Argument 1: cannot convert from 'string' to 'int'

代码:

public partial class neworderForm : Form
{

public neworderForm()
{
    InitializeComponent();
    fillCombo();
}
void fillCombo()
{
    string constring = @"Data Source=|DataDirectory|\LWADataBase.sdf";
    string Query = "select * from stockTBL; ";
    SqlCeConnection conDataBase = new SqlCeConnection(constring);
    SqlCeCommand cmdDataBase = new SqlCeCommand(Query, conDataBase);
    SqlCeDataReader myReader;
    try
    {
        conDataBase.Open();
        myReader = cmdDataBase.ExecuteReader();

        while (myReader.Read())
        {
            string sName = myReader.GetString("[Item Name]");
            comboItem.Items.Add(sName);
        }

        //displays a system error message if a problem is found
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

错误在 string sName = myReader.GetString("[Item Name]");

最佳答案

关于c# - DataTable 列数据到组合框错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22546902/

相关文章:

c# - 当触发另一个类的事件时通知

Mysql 正则表达式匹配最多两个单词的名称

Mysql 与 Node.js : Does it make sense to have node. js 一直在数据库中保存/加载内容?

mysql - Django 查询和存储过程(MySQL)之间的性能差异?

winforms - Windows 窗体设计器中的居中对齐窗体

c# - 如何防止其他 session 在 UPDATE 发生之前选择一行

c# - 托管环境中的临时内存

c# - 用于显示乐谱的库

c# - 可变大小所有者绘制 ComboBox;列表大小不正确

c# - Winforms WebBrowser 控件 URL 参数