2012-12-17 21 views
2

當我嘗試在C#中的Web應用程序中實現下載功能時,出現XML解析錯誤。相同的代碼在另一個Web表單中工作。XMLParsing錯誤

SqlConnection cn = new SqlConnection(); 

cn.ConnectionString =ConfigurationManager.ConnectionStrings["cn"].ConnectionString.ToString(); 
cn.Open(); 

String abc = null; 

SqlCommand cm = new SqlCommand("select User_ID from Mgmt where S_Name='" + DropDownList1.Text + "'", cn); 

SqlDataReader dr = cm.ExecuteReader(); 

if (dr.Read()) 
{ 
    abc = dr.GetString(0).ToString(); 
} 

dr.Close(); 
cm.Dispose(); 

String ab = null; 

SqlCommand cmd = new SqlCommand("select Result from Result where Clg_ID='" + abc + "'and Student_ID='" + TextBox1.Text + "'", cn); 
SqlDataAdapter drr = new SqlDataAdapter(cmd); 

DataSet ds = new DataSet(); 

drr.Fill(ds); 

ab = ds.Tables[0].Rows[0][0].ToString(); 

Response.ContentType = "application/pdf"; 
Response.AppendHeader("Content-Disposition", "attachment; filename='"+ab+"'"); 
Response.TransmitFile(Server.MapPath("~/Result/"+ab)); 
Response.End(); 

cn.Close(); 
+2

你會得到什麼錯誤代碼?一個附註 - 你的代碼對SQL注入atack是開放的。 – Igor

+0

運行此代碼時沒有警告,Web瀏覽器上的輸出是xml分析錯誤。 –

+1

在〜/ Result'位置是否存在名稱存儲在變量'ab'中的文件? – Igor

回答

0

經過很多努力,我得到了一個可能的答案。這不是一個準確的答案。我剛切換了電腦,然後這個錯誤不再發生,並且返回到我以前的電腦,然後錯誤也解決了。我仍然不知道是什麼導致了錯誤,以及它是如何解決的。