我创建了以下存储过程
CREATE PROCEDURE dbo.GetPoint
AS
SELECT point FROM tLocalGeo
现在我需要从C#Controller执行该程序并将数据保存在列表中。
正如你可以看到问题的背景是得到点,然后我可以使用javascript在谷歌地图上显示它们。
你能给我一些参考怎么做吗?我需要SQLReader吗?
感谢您的关注。
答案 0 :(得分:2)
您可以使用 SqlDataAdapter 和 DataSet ,然后可以从数据集的第一个表中获取值。
SqlCommand cmd = new SqlCommand("store procedure Name", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adapter= new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
if(ds.Tables[0]!=null && ds.Tables[0].Rows.Count > 0)
{
//your code
}
希望它有所帮助。
答案 1 :(得分:2)
String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetPoint";
cmd.Parameters.AddWithValue("@EmployeeID", Empid) // ur input parameter//
cmd.Connection = con;
try
{
con.Open();
GridView1.EmptyDataText = "No Records Found";
GridView1.DataSource = cmd.ExecuteReader() ;
GridView1.DataBind();
}