0
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("App_Data\\people.mdb"));
            string command = "SELECT * from Files where FileSubjectID=1"; //1 = newsLetters, 2 = Publications, 3 = Videos, 4 = Presentations, 5 = Brochures, 6 = Others
            OleDbDataReader reader = null;    
            string fileType = string.Empty;
            string fileIcon = string.Empty;
            FileInfo file;

            int count = 0;

            try
            {
                using (conn)
                {
                    using (OleDbCommand cmd = new OleDbCommand(command, conn))
                    {
                        cmd.CommandType = CommandType.Text;
                        conn.Open();
                        reader = cmd.ExecuteReader();

                        Response.Write("bofore whil1e<br/>" + reader.HasRows + "<br/>");
                        while (reader.Read())
                        {

                            file = new FileInfo(reader["FileName"].ToString());
                            fileIcon = setFileTypeIcon(file.Extension.ToLower());

                            Response.Write(count++ + "<br/>");


                            lblNewsLetters.InnerHtml += "<tr><td class='te_al_M'>" +
                                "<table><tr><td rowspan='2'><img src='images/icons/" + fileIcon + ".png'  alt='" + fileIcon + "'/></td><td><span class='te_al_L lblFiles'>" + reader["FileName"].ToString() + "</span></td></td></tr><tr><td><input type='text' style='display:none' id='txtNewName_" + reader["FileID"].ToString() + "'/></td></tr></table></td>" +


                                "<td class='te_al_L' width='150'>" + getUserName(reader["UserID"].ToString()) + "</a></td>" +
                                "<td class='te_al_L' width='70'>" + Convert.ToDateTime(reader["FileUploadDate"].ToString()).ToShortDateString() + "</td>" +
                                "<td class='te_al_L' width='70'><a target='_blank' href='" + reader["FilePath"].ToString() + "''><img src='images/viewBtn.jpg' alt='View file' title='View file'/></a></td>" +
                                "<td class='te_al_L' width='70'><a target='_blank' href='" + reader["FilePath"].ToString() + "''><img src='images/downloadBtn.jpg' alt='Download file' title='Download file'/></a></td>";


                            // only the uploader can change the file name
                            if (isCurrentUsercodeInFile(currentUsercode, reader["FileName"].ToString()))
                            {
                                lblNewsLetters.InnerHtml += "<td class='width_70'>" +
                                    "<a id='rename_" + reader["FileID"].ToString() + "' href='javascript:renameFile(\"" + reader["FileID"].ToString() + "\");'><img src='images/renameBtn.jpg' alt='Rename file' title='Rename file'/></a>" +
                                    "<a style='display:none;' id='save_" + reader["FileID"].ToString() + "' href='javascript:saveFile(\"" + reader["FilePath"].ToString() + "\" , \"" + reader["FileName"].ToString() + "\" , \"" + currentUsercode + "\" , \"" + reader["FileID"].ToString() + "\");'><img  src='images/saveBtn.jpg' alt='Save file' title='Save file'/></a></td>";
                            }
                            else
                            {
                                lblNewsLetters.InnerHtml += "<td class='width_70'>&nbsp;</td>";
                            }


                            // only the uploader can delete the file
                            if (isCurrentUsercodeInFile(currentUsercode, reader["FileName"].ToString()))
                            {
                                lblNewsLetters.InnerHtml += "<td class='width_70'><a href='javascript:delFile(\"" + reader["FilePath"].ToString() + "\" , \"" + reader["FileName"].ToString() + "\" , \"" + currentUsercode + "\");'><img src='images/deleteBtn.jpg' alt='Delete file' title='Delete file'/></a></td></tr>";
                            }
                            else
                            {
                                lblNewsLetters.InnerHtml += "<td class='width_70'>&nbsp;</td></tr>";
                            }
                        }
                        Response.Write("b whil1e<br/>");
                        conn.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                //Response.Write(ex.Message);
                conn.Close();
            }

我有上面的代码,忽略所有的“Response.Write”和拼写它们只是为了我的测试。

我的问题是编码在本地工作而不是在线工作。“while(reader.Read())”未在线执行我看到我在 while 之前的消息,但没有看到 while 循环中的消息,也没有看到 while 循环结束时的消息,而在本地我看到所有消息.

我做错了什么?我为此工作了两天。如果您需要更多代码,请说明需要什么,如果有人问过这个问题,我很抱歉,但我没有找到解决问题的方法。

4

1 回答 1

2

您正在吞下异常:

catch (Exception ex)
{
    //Response.Write(ex.Message);
    conn.Close();
} 

循环开始后您看不到任何内容的原因while可能是抛出了一个异常,但随后又被上面的代码片段吞没了。我会记录异常并分析它。您可能无法找到数据库中指定的文件:

file = new FileInfo(reader["FileName"].ToString());`

因此抛出并失败。永远不要吞下异常!至少记录到一个文件,这样你就可以确定发生了什么。

于 2013-07-09T08:30:08.163 回答