【问题标题】:Why combobox show error System.data.datarowview c#?为什么组合框显示错误 System.data.datarowview c#?
【发布时间】:2018-02-01 13:58:18
【问题描述】:

我需要为患者调查更新组合框机器名称的值,当我从数据库中检索输入的机器名称时,总是出现以下错误 system.data.datarowview。 这是我的代码:

1- 存储过程:

create proc [GET_RESULT_MACHINES]
@Criteria nvarchar(20)
AS 
SELECT machines.machine_id , MACHINE_NAME AS 'MACHINE NAME'  FROM MACHINES
inner join LAB_RESULTS on LAB_RESULTS.machine_id = Machines.Machine_id
where CONVERT(varchar,[LAB_RESULTS].ORDER_ID) = ''+@Criteria+''

2- c#类void:

public DataTable GET_RESULT_MACHINES(string Criteria)
        {
            DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
            DataTable dt = new DataTable();

            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@Criteria", SqlDbType.VarChar,20);
            param[0].Value = Criteria;

            dt = DAL.SelectData("GET_RESULT_MACHINES", param);
            DAL.close();
            return dt;
        }

3- 按 Enter 时 Key_Down 无效代码我正在使用以下代码:

private void txtOrder_KeyDown(object sender, KeyEventArgs e)
        {
            sqlconnection = new SqlConnection(@"server= KAASH-AV-SRV; database=mamlakalab; Integrated Security=true; ");

            if (checkInitialResult.Checked == true && checkApproveResult.Checked == false && txtOrder.Text != string.Empty && e.KeyCode == Keys.Enter )
            {
                dgvResult.DataSource = result.GetOrderForResult(txtOrder.Text);

                comboMachines.DataSource = result.GET_RESULT_MACHINES(txtOrder.Text);
                comboMachines.DisplayMember = "MACHINE_NAME";
                comboMachines.ValueMember = "machine_id";
            }
}

我检查了之前的问题,但找不到答案 请提出您的建议。

【问题讨论】:

  • 我猜问题出在您的 DisplayMember 属性中。在您的存储过程中,您使用别名 MACHINE NAME 并将 DisplayMember 绑定到 MACHINE_NAME(带下划线)。
  • 正确感谢您的工作。但是我现在在组合框中有另一个问题我需要更新值但是使用此代码它只显示选定的值而不显示其他机器名称如何修改代码以显示数据库中的选定值加上所有机器名称我可以更改机器名称吗?
  • 您的组合只显示一个值,因为您的存储过程只返回一条记录。

标签: c# combobox


【解决方案1】:

答案是从机器名称中删除下划线谢谢 Nino

private void txtOrder_KeyDown(object sender, KeyEventArgs e)
        {
            sqlconnection = new SqlConnection(@"server= KAASH-AV-SRV; database=mamlakalab; Integrated Security=true; ");

            if (checkInitialResult.Checked == true && checkApproveResult.Checked == false && txtOrder.Text != string.Empty && e.KeyCode == Keys.Enter )
            {
                dgvResult.DataSource = result.GetOrderForResult(txtOrder.Text);

                comboMachines.DataSource = result.GET_RESULT_MACHINES(txtOrder.Text);
                comboMachines.DisplayMember = "MACHINE NAME";
                comboMachines.ValueMember = "machine_id";
            }
}

【讨论】:

    猜你喜欢
    • 2015-11-22
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多