这是什么原因?????????

chen780831 2002-08-05 02:05:34
用C#写的一段代码,更新数据库中的一行数据信息:
using System;
using System.Data; //Use ADO.NET namespace
using System.Data.SqlClient; //Use SQL Server data provider namespace
namespace DataReaderExample
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
SqlConnection thisConnection=new SqlConnection(
@"Data Source=(local);Integrated Security=SSPI;"+
"Initial Catalog=TestForNet");
//Open connection
thisConnection.Open();

//Create DataAdapter object for update and other operations
SqlDataAdapter thisAdapter=new SqlDataAdapter(
"SELECT CustomerID,CompanyName FROM Customers",thisConnection);
//Create CommandBuider object to build SQL commands
SqlCommandBuilder thisBuilder=new SqlCommandBuilder(thisAdapter);
//Create DataSet to contain related data tables,rows,and columns
DataSet thisDataSet=new DataSet();
//Fill DataSet using query defined previously for DataAdapter
thisAdapter.Fill(thisDataSet,"Customers");
//Show data before change
Console.WriteLine("name before change:{0}",
thisDataSet.Tables["Customers"].Rows[0]["CompanyName"]);
//change data in Customers table,row 0,Companyname column
thisDataSet.Tables["Customers"].Rows[0]["CompanyName"]="Acme,Inc";
//Call Update command to mark change in table
thisAdapter.Update(thisDataSet,"Customers");//在执行此句代码时,出现
//如下错误提示:未处理的“System.InvalidOperationException”类型的异常出
//现在system.data.dll 中
//其他信息:对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand
//的动态 SQL 生成。

Console.WriteLine("name after change:{0}",
thisDataSet.Tables["Customers"].Rows[0]["CompanyName"]);
//Close connection
thisConnection.Close();
}
}
}
请问这是什么原因。
...全文
49 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧