新人求指点:C#文件上传程序出错
这是App_Code中创建的类FileDB.cs
问题都出在这段程序上。加红色为出错地方。
出错原因:Invalid token ’=’ in class, struct, or interface member declaration
Invalid token ’;’ in class, struct, or interface member declaration
Invalid token ’try’ in class, struct, or interface member declaration
Invalid token ’(’ in class, struct, or interface member declaration
Expected class,delegate,enum,interface,or struct
A namespace does not directly contain members such as fields or methods
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();
SqlConnection myConnection=new SqlConnection(SQLCONNECTIONSTRING);
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
//
}