PDA

View Full Version : خواندن از بانک اطلاعاتی



sard69
یک شنبه 09 بهمن 1390, 16:16 عصر
string ad_book;
string book_name;
string ad_pic;
string pic_name;
int id;
if (Request.QueryString["type"] == "")
{
Response.Redirect("menu.aspx");
return;

}
SqlDataReader myreader;
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select * from download where type=@type";
cmd.Parameters.AddWithValue("@type", Request.QueryString["type"].ToString());
con.Open();
myreader = cmd.ExecuteReader();
while (myreader.Read())
{
if (myreader["type"].ToString() == Request.QueryString["type"].ToString())
{

id = Convert.ToInt16(myreader["id"].ToString());
ad_book = myreader["ad_file"].ToString();
book_name = myreader["name_file"].ToString();
ad_pic = myreader["ad_pic"].ToString();
pic_name = myreader["name_pc"].ToString();
if (ad_book.StartsWith("example") && System.IO.File.Exists(Request.PhysicalApplicationP ath + "book_file\\" + book_name))//book file
{
System.IO.File.Delete(Request.PhysicalApplicationP ath + "book_file\\" + book_name);
}
if (ad_pic != "example" && ad_pic.StartsWith("example") && System.IO.File.Exists(Request.PhysicalApplicationP ath + "book_images\\" + pic_name))//pic file
{

System.IO.File.Delete(Request.PhysicalApplicationP ath + "book_images\\" + pic_name);

}

cmd.CommandText = "delete from download where id=@id";
cmd.Parameters.AddWithValue("@id", id);
cmd.ExecuteNonQuery();

}
else
{
continue;
}


}
con.Close
();


سلام مشکل این کد چیه ارور میده ابتدا کانکشن رو باز کنین

xalerebvar
یک شنبه 09 بهمن 1390, 16:33 عصر
دوست عزیز لطفا کدهای تان را داخل تگ ها قرار دهید و بگید که چه اروری می ده