新人求指点:C#文件上传程序出错

flowerontheroad 2010-09-24 07:59:55
这是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
//


}
...全文
95 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
flowerontheroad 2010-09-24
  • 打赏
  • 举报
回复
.......身边的也都是菜鸟。。。。
hchxxzx 2010-09-24
  • 打赏
  • 举报
回复
这还真是手把手教啊,同志.
先向你身边的人请教一下吧,这网上一来一去的,时间耗不起啊.
flowerontheroad 2010-09-24
  • 打赏
  • 举报
回复
改完这些之后,我的upFile.aspx.cs就出了问题
if (File.Exists(Server.MapPath(Request.ApplicationPath) + "\\UpLoads" + fileName) == false)
说是当前上下文中不存在名称File。

真是命途多舛啊
wuyq11 2010-09-24
  • 打赏
  • 举报
回复
SqlCommand MyCommand = new SqlCommand("", conn);
MyCommand.CommandType = CommandType.StoredProcedure;

MyCommand.ExecuteReader();
flowerontheroad 2010-09-24
  • 打赏
  • 举报
回复
还是有错。。。抑郁
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 指令或程序集引用?)


huangwenquan123 2010-09-24
  • 打赏
  • 举报
回复
你鼠标移到SqlDataReader会自动提示!
huangwenquan123 2010-09-24
  • 打赏
  • 举报
回复
添加命名空间using System.Data.SqlClient;
flowerontheroad 2010-09-24
  • 打赏
  • 举报
回复
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 指令或程序集引用?)
flowerontheroad 2010-09-24
  • 打赏
  • 举报
回复
照你的改完之后,又发生以下问题了
1、应输入类型、命名空间定义或文件尾
2、Type or namespace definition or end-of-file expected
该怎么办呢???
wuyq11 2010-09-24
  • 打赏
  • 举报
回复
public SqlDataReader GetFiles()
{
using(SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ToString()))
{
conn.Open();
SqlCommand MyCommand = new SqlCommand("MYSQL", conn);
MyCommand.CommandType = CommandType.StoredProcedure;
...
}

...
}

wuyq11 2010-09-24
  • 打赏
  • 举报
回复
using(SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ToString()))
{
conn.Open();
SqlCommand MyCommand = new SqlCommand("MYSQL", conn);
MyCommand.CommandType = CommandType.StoredProcedure;
...
}
检查连接字符串
内容概要:SSD2828QN4是一款MIPI主桥接芯片,用于连接应用处理器与传统并行LCD接口及支持MIPI从属接口的LCD驱动器。该芯片支持最高每通道1Gbps的串行链路速度,最多可配置4个数据通道,显著减少了信号数量。它支持多种接口模式,包括RGB+SPI组合接口,适用于驱动智能或非智能显示面板,并能通过命令模式和视频模式传输数据。芯片内置时钟和复位模块、外部接口、协议控制单元(PCU)、包处理单元(PPU)、错误校正码/循环冗余校验(ECC/CRC)模块、长包和命令缓冲区、D-PHY控制器、模拟收发器以及内部锁相环(PLL),确保了高效的数据传输和系统稳定性。此外,文档详细描述了芯片的引脚分配、寄存器设置、操作模式、电源序列、时序特性等关键参数,为开发者提供了全面的技术指导。 适合人群:具备一定硬件设计基础,从事嵌入式系统开发、显示技术研究的研发人员。 使用场景及目标:①实现应用处理器与MIPI兼容显示屏之间的高速数据传输;②优化显示系统的功耗表现,减少电磁干扰(EMI);③通过灵活配置不同接口模式来适应各种显示设备的需。 阅读建议:此文档面向具有一定电子工程背景的专业人士,建议读者结合实际项目需深入理解各章节内容,特别是关于寄存器配置、时序要等方面的具体说明。对于初次接触此类技术的开发者而言,建议先熟悉基本概念再逐步掌握高级功能的应用方法。

62,271

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧