一个自己写的Webmethod,运行时老是报错,高手请指正
public int[] ID(decimal jingdu,decimal weidu)
{
//int i = 0;
int[] s ={ 0, 0, 0 };
string strconn = "Data Source=ANDY;Initial Catalog=GUIDE;Integrated Security=True ";
SqlConnection conn = new SqlConnection(strconn);
string sqlstr = "select top 3 ID from andy order by square(longitude-@jing)+square(latitude-@wei) ";
SqlDataAdapter da=new SqlDataAdapter(sqlstr,strconn);
DataSet ds = new DataSet();
da.Fill(ds, "andy ");
DataTable dt = ds.Tables[ "andy "];
for (int i = 0; i < dt.Rows.Count; i++)
{
s[i] = (int)dt.Rows[i][ "ID "];
}
return s;
}
编译成功,但在运行时出现如下错误:
System.Data.SqlClient.SqlException: 必须声明标量变量 "@jing"。
------解决方案--------------------string sqlstr = "select top 3 ID from andy order by square(longitude-@jing)+square(latitude-@wei) ";
这句里面你用到了2个变量@jing @wei
可是你在后面似乎没有给这两个变量数值就直接运行了指令。