问题描述
请帮我修改一下,如何插入reader1里的全部数据#include"stdafx.h"#using<mscorlib.dll>usingnamespaceSystem::Data;usingnamespaceSystem::Data::SqlClient;usingnamespaceSystem;int_tmain(){String*str[]={S"",S"",S""};try{intlen;SqlConnection*sql=newSqlConnection();sql->ConnectionString=S"workstationid=sa;packetsize=4096;userid=sa;datasource=ADMIN-82B030BB5;initialcatalog="students";password=123";sql->Open();SqlCommand*cmd=newSqlCommand();SqlCommand*cmd1=newSqlCommand();cmd->CommandText=S"insertintostud([id],[name],[age])values(@id,@name,@age)";cmd1->Connection=sql;cmd1->CommandText=S"selectid,name,agefromstu";cmd->Connection=sql;System::Data::SqlClient::SqlParameter*tran=newSqlParameter();System::Data::SqlClient::SqlDataReader*reader1=cmd1->ExecuteReader();len=reader1->FieldCount;while(reader1->Read()){for(inti=0;i<len;i++){str[i]=reader1->Item[i]->ToString();Console::Write(str[i]);}Console::WriteLine();}tran=newSqlParameter("@id",SqlDbType::Char);cmd->Parameters->Add(tran);tran->set_Value(str[0]);tran=newSqlParameter("@name",SqlDbType::Char);cmd->Parameters->Add(tran);tran->set_Value(str[1]);tran=newSqlParameter("@age",SqlDbType::Char);cmd->Parameters->Add(tran);tran->set_Value(str[2]);reader1->Close();cmd->ExecuteNonQuery();sql->Close();}catch(Exception*e){Console::WriteLine(e->ToString());}return0;}
解决方案
解决方案二:
路过帮顶=============11月6日,论坛升级公告,积分已经做了调整!http://topic.csdn.net/u/20081107/11/b27dc75f-14b1-4594-9de3-5b18d9e36a11.html此次调整增加了两个新的可用分获取渠道:1:帖子被推荐(加精)后,帖主可以获得88分的可用分奖励;2:帖子结帖后会返还帖主50%的悬赏分,无满意结帖不返还分数;3:接下来会不断增加新的可用分获取途径,比如参与活动赠送等,请大家多关注;