找不到第0列。

编程入门 行业动态 更新时间:2024-10-20 07:43:20
本文介绍了找不到第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列。

本文发布于:2023-07-04 17:13:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026919.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!