大家看一看这个查询语句那里错了! 高手加!!! 急!!!!!
public SqlDataReader createTest(string courseId,string type,int number)
{
SqlConnection myConnection=new SqlConnection(ConfigurationSettings.AppSettings[ "strConn "]);
myConnection.Open();
string sql = @ "SELECT TOP @number *
FROM test
WHERE (testCourse = @courseId) AND (pub = 1)
AND (typeofproblem = @type) ";
SqlCommand myCommand=new SqlCommand( "sql ",myConnection);
myCommand.Parameters.Add( "@courseId ",SqlDbType.VarChar,20).Value=courseId;
myCommand.Parameters.Add( "@type ", SqlDbType.VarChar, 20).Value = type;
myCommand.Parameters.Add( "@number ", SqlDbType.Int, 10).Value = number;
SqlDataReader reader = myCommand.ExecuteReader();
myConnection.Close();
提示: 'Sql '附近语法有错误!是不是查询语句中number不能这么用??
如何解决???在线等!!
------解决方案--------------------SqlCommand myCommand=new SqlCommand(sql,myConnection);
------解决方案--------------------sql 不是在上面定义了的吗?
你那样写就把字符串sql传进去了
------解决方案--------------------。。。。。。楼主 写程序 要认真些哦 这是没必要的错误