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+"%'";
添加回答
举报
0/150
提交
取消