Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#和SQL Server:如何通过使用C#调用存储过程从SQL表中获取值?_C#_Sql_Google Maps_Stored Procedures - Fatal编程技术网

C#和SQL Server:如何通过使用C#调用存储过程从SQL表中获取值?

C#和SQL Server:如何通过使用C#调用存储过程从SQL表中获取值?,c#,sql,google-maps,stored-procedures,C#,Sql,Google Maps,Stored Procedures,我创建了以下存储过程 CREATE PROCEDURE dbo.GetPoint AS SELECT point FROM tLocalGeo 现在我需要从我的C#控制器执行该过程,并将数据保存在列表中 正如您所看到的,问题的背景是获取点,然后我可以使用javascript在google地图上显示它们 你能给我一些如何做的参考资料吗?我需要SQLReader吗 感谢您的关注。您可以使用SqlDataAdapter和DataSet,然后可以从DataSet的第一个表中获取值。 希望有帮

我创建了以下存储过程

CREATE PROCEDURE dbo.GetPoint
AS
    SELECT point FROM tLocalGeo
现在我需要从我的C#控制器执行该过程,并将数据保存在列表中

正如您所看到的,问题的背景是获取点,然后我可以使用javascript在google地图上显示它们

你能给我一些如何做的参考资料吗?我需要SQLReader吗


感谢您的关注。

您可以使用SqlDataAdapterDataSet,然后可以从DataSet的第一个表中获取值。


希望有帮助。

您可以使用SqlDataAdapterDataSet,然后可以从DataSet的第一个表中获取值。
  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(); 
   }


希望能有所帮助。

很抱歉花了这么长时间才回复。我将ds对象返回到我的视图,这可能吗?这样我就可以在脚本中创建一个foreach语句来显示googlemap上的所有标记。返回视图(ds);是的,您可以将数据集返回视图,也可以将其转换为列表,并将该列表传递给视图。请参阅以查看数据集@M.Coutinho:还有任何困惑吗?不,谢谢,我只是这里有另一个问题@M.Coutinho:养成接受答案的习惯,如果答案对你有用的话,那么你也可以增加对你的问题的回答,因为回答时间太长了。我将ds对象返回到我的视图,这可能吗?这样我就可以在脚本中创建一个foreach语句来显示googlemap上的所有标记。返回视图(ds);是的,您可以将数据集返回视图,也可以将其转换为列表,并将该列表传递给视图。请参阅以查看数据集@M.Coutinho:还有任何困惑吗?不,谢谢,我只是这里有另一个问题@M.Coutinho:养成接受答案的习惯,如果答案对你有用,那么你也可以增加对问题的回答
  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(); 
   }