求助,把查找出的数据插入一张新的表中,方法要怎么写,或者SQL语句执行插入的命令的是什么?

[复制链接]
查看11 | 回复2 | 2011-7-28 18:16:03 | 显示全部楼层 |阅读模式
{strQuery = " select top 1 值1,值2 from 信息表 where 功能 ='";

strQuery += this.textBox1.Text;

strQuery += "'";

strQuery += " order by 值3 desc"; //这段是查找数据

InsertRecord();

}

public bool InsertRecord()

{

SqlConnection thisConnection = new SqlConnection("integrated security=SSPI;data source=.;persist security info=False;initial catalog=FunctionVector");

bool bRet = false;        //定义返回值

//构造操作sql语句

string strSQL = "insert into 信息表2(值1,值2)";

strSQL += strQuery; // strQuery为上面查找的字符串

//递交sql操作,执行无记录返回的操作,返回值表征操作是否成功

SqlCommand cmd = new SqlCommand(strSQL, thisConnection);

return bRet;

}
这个方法感觉是有错误的,表2中一直没有数据,求帮助!

回复

使用道具 举报

千问 | 2011-7-28 18:16:03 | 显示全部楼层
修改内容参考{strQuery = " select top 1 值1,值2 from 信息表 where 功能 ='";
strQuery += this.textBox1.Text;
strQuery += "'";
strQuery += " order by 值3 desc"; //这段是查找数据
InsertRecord(strQuery );
} public bool InsertRecord(string strQuery)
{
SqlConnect...
回复

使用道具 举报

千问 | 2011-7-28 18:16:03 | 显示全部楼层
语法没问题strQuery = " select top 1 值1,值2 from 信息表 where 功能 ='";

大概是因为这是个全角的=号...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行