未处理的“System.NullReferenceException”类型的异常出现在 System.Data.dll 中
usingnamespaceSystem;usingnamespaceSystem::ComponentModel;usingnamespaceSystem::Colle...
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::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(); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询