本帖最后由 flowerontheroad 于 2010-09-24 20:07:00 编辑

解决方案 »

  1.   

    using(SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ToString()))
    {
    conn.Open();
    SqlCommand MyCommand = new SqlCommand("MYSQL", conn);
    MyCommand.CommandType = CommandType.StoredProcedure;
    ...
    }
    检查连接字符串
      

  2.   

    public SqlDataReader GetFiles()
    {
     using(SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ToString()))
    {
    conn.Open();
    SqlCommand MyCommand = new SqlCommand("MYSQL", conn);
    MyCommand.CommandType = CommandType.StoredProcedure;
    ...
    }...
    }  
     
      

  3.   

    照你的改完之后,又发生以下问题了
    1、应输入类型、命名空间定义或文件尾
    2、Type or namespace definition or end-of-file expected
    该怎么办呢???
      

  4.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;/// <summary>
    /// Summary description for Class1
    /// </summary>
    public class FileDB
    {
    public FileDB()
    {}
            public static string SQLCONNECTIONSTRING = ConfigurationSettings.AppSettings["SQLCONNECTIONSTRING"].ToString();
            public SqlDataReader GetFiles()
            {
               using(SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ToString()))
                {
                  conn.Open();
                  SqlConnection myCommand=new SqlCommand("Pr_GetFiles",myConnection);
                  myCommand.CommandType = CommandType.StoredProcedure;
                  SqlDataReader dr=null;
                  try{ myConnection.Open();}
                  catch (Exception ex) { throw new Exception("数据库连接失败!",ex);}
                                       
                  try
                     {
                       dr=myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                     }
                    catch(Exception ex){throw new Exception(ex.Message,ex);}
                    return(dr);
                  }
              }
                public int AddFile(String sFileName,String sFileUrl,String sFileKind)
                {
                    SqlConnection myConnection=new SqlConnection(SQLCONNECTIONSTRING);
                    SqlCommand myCommand=new SqlCommand("Pr_AddFile",myConnection);
                    SqlParameter parameterFileID=new SqlParameter("@FileID",SqlDbType.Int,4);
                    parameterFileID.Direction=ParameterDirection.ReturnValue;
                    myCommand.Parameters.Add(parameterFileID);
                    try{myConnection.Open();}
                    catch(Exception ex){throw new Exception("数据库连接失败!",ex);}
                    try{myCommand.ExecuteNonQuery();}
                    catch(Exception ex){throw new Exception(ex.Message,ex);}
                    return(int)parameterFileID.Value;
                }

    //
    // TODO: Add constructor logic here
    //
    }
    改成这样之后报错说找不到类型或命名空间名称“SqlDataReader”(是否缺少 using 指令或程序集引用?)
      

  5.   

    添加命名空间using System.Data.SqlClient;
      

  6.   

    你鼠标移到SqlDataReader会自动提示!
      

  7.   

    还是有错抑郁
    1、无法将类型“System.Data.SqlClient.SqlCommand"隐式转换为“System.Data.SqlClient.SqlConnection"
    2、“System.Data.SqlClient.SqlConnection"不包含“commandType"的定义,并且找不到可接受类型为“System.Data.SqlClient.SqlConnection"的第一个参数的扩展方法“commandType"(是否缺少 using 指令或程序集引用?)3、、“System.Data.SqlClient.SqlConnection"不包含“ExecuteReader"的定义,并且找不到可接受类型为“System.Data.SqlClient.SqlConnection"的第一个参数的扩展方法“ExecuteReader"(是否缺少 using 指令或程序集引用?)
      

  8.   

    SqlCommand MyCommand = new SqlCommand("", conn);
    MyCommand.CommandType = CommandType.StoredProcedure;MyCommand.ExecuteReader();
      

  9.   

    改完这些之后,我的upFile.aspx.cs就出了问题
    if (File.Exists(Server.MapPath(Request.ApplicationPath) + "\\UpLoads" + fileName) == false)
    说是当前上下文中不存在名称File。真是命途多舛啊