为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕盖茨4494581 2022-04-07 11:07:52
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);//数据库采用集成认证方式,数据源为本地数据库,数据库名为daSqlCommandBuilder^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 回答

?
忽然笑

TA贡献1806条经验 获得超5个赞

已经解答了 下面语句有错
st1=L"select * from KC where km like'"+textBox1->Text+"%";
修改成
st1=L"select * from KC where km like '"+textBox1->Text+"%'";

查看完整回答
反对 回复 2022-04-11
  • 1 回答
  • 0 关注
  • 472 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信