怎么在代码中调用存储过程
namespace ConsoleApplication23
{
class Program
{
static void Main(string[] args)
{
List<string> list = ReturnCheckArea("东四", "", "乡", "镇", "街道", "区").ToList();
List<string> list1 = ReturnCheckArea("海城", "县", "区", "市", "").ToList();
List<string> list2 = ReturnCheckArea("鞍山", "市", "").ToList();
List<string> list3 = ReturnCheckArea("辽宁", "省", "").ToList();
string temp = string.Empty;
for (int i = 0; i < list.Count; i++)
{
for (int j = 0; j < list1.Count; j++)
{
for (int k = 0; k < list2.Count; k++)
{
for (int m = 0; m < list3.Count; m++)
{
temp=SelectStrStreet(list[i], list1[j], list2[k], list3[m]);
if (temp.Length <= 0)
{
continue;
}
else
{
return;
}
}
}
}
}
}
private static string SelectStrStreet(string street, string xian, string city, string prov)
{
string retStr = "";
using (SqlConnection sqlconn = new SqlConnection("Data Source=ZHANG-PC;Initial Catalog=config;Integrated Security=True"))
{
sqlconn.Open();
using (SqlCommand cmd = sqlconn.CreateCommand())
{
string sql = "ChechArear";
cmd.CommandText = sql;
cmd.CommandType = CommandType.StoredProcedure;
IDataParameter[] parameters = {
new SqlParameter("@street", SqlDbType.NVarChar,50) ,
new SqlParameter("@county", SqlDbType.NVarChar,50) ,
new SqlParameter("@city",SqlDbType.NVarChar,50),
new SqlParameter("@prov",SqlDbType.NVarChar,50),
new SqlParameter("@inReturn",SqlDbType.NVarChar,50)};
parameters[0].Value = street;
parameters[1].Value = xian;
parameters[2].Value = city;
parameters[3].Value = prov;
parameters[4].Direction = ParameterDirection.Output;
cmd.Parameters.AddRange(parameters);
cmd.ExecuteNonQuery();
retStr = parameters[4].Value.ToString();
}
return retStr;
}
}
private static IList<string> ReturnCheckArea(string temparea, params string[] strs)
{
List<string> list = new List<string>();
if (strs.Length <= 0)
{
list.Add(temparea);
return list;
}
foreach (string s in strs)
{
list.Add(temparea + s);
}
return list;
}
}
}