sql 高手进!select top n 语句该怎么写?解决后额外加分!!!
stringcc,dd,ee;cc=this.TextBox2.Text;//编号dd=this.TextBox3.Text;//预测年份ee=this.TextBox4...
string cc,dd,ee;
cc = this.TextBox2.Text;//编号
dd = this.TextBox3.Text;//预测年份
ee = this.TextBox4.Text;//预测步长
//int n = (int)ee;
int n = Convert.ToInt32(ee);
string ff = "select top n LSXQ from yuce where BJBH ='" + this.TextBox2.Text + "' and LSNF<'" + this.TextBox3.Text + "' order by LSNF desc ";
SqlConnection scon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
scon.Open();
SqlDataAdapter dbAdapter = new SqlDataAdapter(ff, scon);
DataSet ds = new DataSet();
dbAdapter.Fill(ds);
scon.Close();
运行后提示n附近有语法错误!!! 展开
cc = this.TextBox2.Text;//编号
dd = this.TextBox3.Text;//预测年份
ee = this.TextBox4.Text;//预测步长
//int n = (int)ee;
int n = Convert.ToInt32(ee);
string ff = "select top n LSXQ from yuce where BJBH ='" + this.TextBox2.Text + "' and LSNF<'" + this.TextBox3.Text + "' order by LSNF desc ";
SqlConnection scon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
scon.Open();
SqlDataAdapter dbAdapter = new SqlDataAdapter(ff, scon);
DataSet ds = new DataSet();
dbAdapter.Fill(ds);
scon.Close();
运行后提示n附近有语法错误!!! 展开
1个回答
展开全部
string ff = "select top" + n.ToString() + " n LSXQ from yuce where BJBH ='" + this.TextBox2.Text + "' and LSNF<'" + this.TextBox3.Text + "' order by LSNF desc ";
追问
我在上面定义n为int型了," + n.ToString() + " 的意思是把n转为字符型吗,那我上面还用定义n吗
追答
是的。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询