ExecuteReader:CommandText属性尚未初始化

本文关键字:初始化 属性 CommandText ExecuteReader | 更新日期: 2023-09-27 18:24:23

我已经做了几个小时的研究,但似乎没有什么适用于我目前的情况。

使用:Visual Studio 2010.net 4.0,语言:C#

问题:

我创建了一个表单,然后将特定表从数据源拖放到表单上,让VS2010为我创建数据表。

当我试图使用数据表更改或添加值到数据库时,我得到了上面列出的错误

"ExecuteReader:CommandText属性尚未初始化"。

根据我之前的研究,否,我没有定义CommandText,也不知道在哪里创建CommandText,因为VS2010创建了所有的数据表代码,并且没有在.cs文件中列出它。

通过点击f7 从表单中获得的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace mineral_monitor.Manual_edits
{
    public partial class mineral_stock : Form
    {
    public mineral_stock()
    {
        InitializeComponent();
    }
    private void mineralsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
    {
        this.Validate();
        this.mineralsBindingSource.EndEdit();
        this.tableAdapterManager.UpdateAll(this.ore_stockDataSet1);
    }
    private void mineral_stock_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'ore_stockDataSet1.minerals' table. 
        // You can move, or remove it, as needed.
        this.mineralsTableAdapter.Fill(this.ore_stockDataSet1.minerals);
    }
   }
}

这是通过在数据设计器中手动创建更新字符串来解决的。

ExecuteReader:CommandText属性尚未初始化

创建数据源时,VisualStudio会自动为您创建select命令,而update、insert和delete命令则不会。您必须手动或使用SqlCommandBuilder指定它们。查看此链接。