“System.NullReferenceException”类型的异常,该如何解决?

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();

慕盖茨4494581
浏览 473回答 1
1回答

忽然笑

已经解答了 下面语句有错st1=L"select * from KC where km like'"+textBox1->Text+"%";修改成st1=L"select * from KC where km like '"+textBox1->Text+"%'";
打开App,查看更多内容
随时随地看视频慕课网APP