未处理的“System.InvalidOperationException”类型的异常出现在 System.Data.dll 中。 5
其他信息:对于不返回任何键列信息的SelectCommand,不支持UpdateCommand的动态SQL生成。usingnamespaceSystem;usingnam...
其他信息: 对于不返回任何键列信息的 SelectCommand,不支持 UpdateCommand 的动态 SQL 生成。
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Data::SqlClient;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
String^st1;
String^secn;
SqlConnection^sqlc;
SqlDataAdapter^sqld1;
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
st1=L"select * from KC where km like'"+textBox1->Text+"%";//%可通配任意字符,以实现对姓名的查询
secn=L"integrated security =SSPI;data source=.;initial catalog=da";
sqlc=gcnew SqlConnection(secn);
sqld1=gcnew SqlDataAdapter(st1,sqlc);//数据库采用集成认证方式,数据源为本地数据库,数据库名为da
SqlCommandBuilder^builder2=gcnew SqlCommandBuilder(sqld1);
this->dataSet1->Clear();
sqld1->Fill(dataSet1,"KC");
this->bindingSource1->DataSource=this->dataSet1->Tables[1];//生成单表命令,以便对DataSet所做的更改与关联的SQL Server数据库的更改相协调
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
this->sqld1->Update(dataSet1,"KC");
sqlc->Close(); 展开
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Data::SqlClient;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
String^st1;
String^secn;
SqlConnection^sqlc;
SqlDataAdapter^sqld1;
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
st1=L"select * from KC where km like'"+textBox1->Text+"%";//%可通配任意字符,以实现对姓名的查询
secn=L"integrated security =SSPI;data source=.;initial catalog=da";
sqlc=gcnew SqlConnection(secn);
sqld1=gcnew SqlDataAdapter(st1,sqlc);//数据库采用集成认证方式,数据源为本地数据库,数据库名为da
SqlCommandBuilder^builder2=gcnew SqlCommandBuilder(sqld1);
this->dataSet1->Clear();
sqld1->Fill(dataSet1,"KC");
this->bindingSource1->DataSource=this->dataSet1->Tables[1];//生成单表命令,以便对DataSet所做的更改与关联的SQL Server数据库的更改相协调
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
this->sqld1->Update(dataSet1,"KC");
sqlc->Close(); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询