注册 登录
编程论坛 ACCESS论坛

写入Access数据库的问题

专发表情 发布于 2008-08-24 20:23, 1698 次点击
原本想着很简单的问题,只是在上用几个textBox的text内容,写入到数据库中设置好的空表,
本代码在CLR上,不是基于MFC,希望注意,
代码如下:
System::String ^strCon ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\weather_report.mdb";

System::String ^ strCom =  "INSERT INTO weather_report (Day, time, city, weather,temp,wind)"
                             "VALUES( '2001/12/25 20:30:15', '夜', 'guangzhou','SUN','32','无')";
 OleDbConnection^ myConn = gcnew OleDbConnection(strCon);
             myConn->Open();

            //打开数据链接,得到一个数据集
          // OleDbDataAdapter ^myCommand = gcnew OleDbDataAdapter(strCom, myConn);       
           myConn->Close();
编译通过,但是Access还是没更新
敢问大伙,谁知道原因??告诉下。
3 回复
#2
专发表情2008-08-24 20:24
都试过用update,但还是一样

System::String ^strCon ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\weather_report.mdb";
            
            //System::String ^ strCom =  "INSERT INTO weather_report (Day, time, city, weather,temp,wind)  VALUES ('000','000','000','000','000','000')";
            
            System::String ^ strCom =  ""UPDATE weather_report SET city = 'Engineering'";
            OleDbConnection^ myConn = gcnew OleDbConnection(strCon);

          // OleDbCommand^insertcommand=gcnew OleDbCommand(strCom,myConn);

        
           myConn->Open();
           //insertCommand->ExecuteNonQuery();

          OleDbConnection^UpdataCommand1=gcnew OleDbConnection(strCom,myConn);
          
           myConn->Close();
#3
专发表情2008-08-24 20:34
表名为:weather_report
项有:Day, time, city, weather,temp,wind
#4
专发表情2008-08-24 21:02
写入数据库记得是
update,或者是insert into
1