ExecuteReader:CommandText 属性尚未初始化

发布于 2025-01-05 09:32:13 字数 1332 浏览 0 评论 0原文

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

使用: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);
    }
   }
}

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

I've done a few hours of research but nothing seems to apply to my current situation.

Using: Visual Studio 2010 .net 4.0,
Language: C#

Issue:

I created a form and then drag and dropped the Specific Table from my Datasources onto the form to have VS2010 create the data table for me.

When I attempted to change or add values to the database using the data table, I get the error listed above

"ExecuteReader: CommandText property has not been initialized".

As from my previous research, NO, I have not defined a CommandText nor do I know where to create one considering VS2010 created all the datatable code and does not list it in the .cs file itself.

Code obtained from form by hitting 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);
    }
   }
}

This was resolved by creating an update string manually in the data designer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尾戒 2025-01-12 09:32:13

创建数据源时,VisualStudio 会自动为您创建选择命令,但不会创建更新、插入和删除命令。您必须手动指定它们或使用 SqlCommandBuilder。查看链接。

When you create a data source, select command is automatically created for you by VisualStudio, but update, insert and delete commands are not. You will have to specify them manually or using SqlCommandBuilder. Check out this link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文