PDA

View Full Version : سوال: ساخت Stored Procedure



noth50
دوشنبه 29 مهر 1392, 10:37 صبح
سلام
به دلیل عوض کردن ویندوز تمامی اطلاعات sql پاک شده . :اشتباه:
آیا کسی هست کمک کنه برای برنامه زیر به چه صورت باید یک Stored Procedure نوشت .


public void CrawlerBranch(int ParentId, int CrawlerCheck)
{
List<MyList> lst = new List<MyList>();
SqlDataReader get = ClassBase.EReader("selecfirstvalue", System.Data.CommandType.StoredProcedure, new SqlParameter[]
{
new SqlParameter("@ParentId",ParentId),
new SqlParameter("@CrawlerCheck",CrawlerCheck)
});

while (get.Read())
{
lst.Add(new MyList(Convert.ToInt32(get["Categories"]), "", 0, get["Url"].ToString(), Convert.ToInt32(get["Categories"])));
}
get.Close();


foreach (MyList list in lst)
{
ClassBase.ENonQuery("updatecrawlercheck", System.Data.CommandType.StoredProcedure, new SqlParameter[]
{
new SqlParameter("@CrawlerCheck",1),
new SqlParameter("@Categories",list.CatID)
});
Crawler(list.Url, list.CatID);
CrawlerBranch(list.CatID, 0);
}


}


این هم کد های SqlDataReader


public static SqlDataReader EReader(string commandText, CommandType commandType, SqlParameter[] commandParameters)
{
SqlConnection con = new SqlConnection(ConnectionString);

SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = commandType;
cmd.CommandText = commandText;
cmd.Parameters.AddRange(commandParameters);

bool mustCloseConnection = false;
try
{

if (con.State != ConnectionState.Open)
{
mustCloseConnection = true;
con.Open();
}
else
{
mustCloseConnection = false;
}

SqlDataReader dataReader;

dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

return dataReader;
}
catch
{
if (mustCloseConnection)
con.Close();
throw;
}


}

}

باتشکر