【发布时间】:2012-02-14 15:05:58
【问题描述】:
我已经做了几个小时的研究,但似乎没有什么适用于我目前的情况。
使用:Visual Studio 2010 .net 4.0, 语言:C#
问题:
我创建了一个表单,然后将特定表从我的数据源拖放到表单上,让 VS2010 为我创建数据表。
当我尝试使用数据表向数据库更改或添加值时,我收到上面列出的错误
“ExecuteReader: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);
}
}
}
已通过在数据设计器中手动创建更新字符串来解决此问题。
【问题讨论】:
-
CommandText = ????请发布您的代码.. CommandType = ???
-
适配器负责将命令文本传递给命令对象。因此,您的适配器中可能缺少
SelectCommand。 -
@WiktorZychla - 当我在数据设计器中查看 TableAdapter 属性时,它确实声明它具有选择、插入和更新命令。
标签: c# visual-studio-2010 ado.net