找不到第0列。 [英] Cannot find column 0.

查看:131
本文介绍了找不到第0列。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void txtAdd_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        if (txtAdd.Text != string.Empty && txtSahr.Text != string.Empty)
        {

            DataRow r = dt.NewRow();

            r[0] = txtNameMada.Text;
            r[1] = txtSahr.Text;
            r[2] = txtAdd.Text;
            r[3] = txtAdd_all.Text;

            cleartext();

            dt.Rows.Add(r);
            dataGridView6.DataSource = dt;
            txtsum.Text =
                   (from DataGridViewRow row in dataGridView6.Rows
                    where row.Cells[3].FormattedValue.ToString() != string.Empty
                    select Convert.ToDouble(row.Cells[3].FormattedValue)).Sum().ToString("0,0");

        }
        else
        {
            MessageBox.Show("ادخال كمية من العدد");
            //  txtAdd_Karton.Focus();
            txtAdd.Clear();
            return;
        }
    }
}





我尝试了什么:





What I have tried:

Cannot find column 0.

推荐答案

如果此行发生错误:
r[0] = txtNameMada.Text;

然后表格是空的:它不包含任何列,因此没有数据。



因为它是一个类级变量,所以我首先看一下加载它的方法首先,因为它建立了表的模式 - 如果你在你的方法中创建一个名为dt的局部变量:

Then the table is empty: it contains no columns, and hence no data.

Since it is a class level variable, I'd start by looking at the method where you load it in the first place, because that establishes the schema for the table - and if you create a local variable called dt within your method:

private DataTable dt = new DataTable();
void MyMethod(void)
   {
   DataTable dt = new DataTable();
   myDataAdapter.Fill(dt);
   ...
   }

然后掩盖了类级别版本,它永远不会被任何模式填充,更不用说数据了。

Then that masks the class level version and it never gets filled with any schema, much less data.


这篇关于找不到第0列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆