日期:2014-05-18  浏览次数:21147 次

初学提问 按照书本敲 也显示了错误
编译错误 
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 

编译器错误信息: CS1518: 应输入 class、delegate、enum、interface 或 struct

源错误:

 

行 17: }
行 18: }
行 19: protected void btnValidate_Click(Object sender,EventArgs e)
行 20: {
行 21: int i=userNameValidate();
 

源文件: e:\My Documents\Visual Studio 2005\WebSites\WebSite1\Register.aspx.cs 行: 19 
C# code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
protected void btnValidate_Click(Object sender,EventArgs e)
{
int i=userNameValidate();
}
///<summary>
///验证用户是否存在
///</summary>
public int userNameValidate()
{
sqlConnection conn=new sqlConnextion(ConfigurationManager.Appsettings["DBConnectionString"]);
SqlCommand selecCmd =new SqlCommand("select * from Users where  userId='"+txtName.Text.Trim()+"'",conn);
int i=0;
try{
conn.open();
SqlDataReader sdr = SelectCmd.ExecuteReader();
if (sdr.Read())
{
int i=1;
lblMessage.Text="此用户已存在,请输入其他用户名";
}
else{
lblMessage.Text="此用户名是可用的!";
}
}
catch(System.exception ee){
Response.write("<script language=javascript>alert('"+ee.Message.toString+"')</script>");

}
finally{
conn.Close;
}
}


------解决方案--------------------
把第18行的大括号移到最后面
------解决方案--------------------
sqlConnection conn=new sqlConnextion(ConfigurationManager.Appsettings["DBConnectionString"]);
写错字母了 是 sqlConnection 不是 sqlConnextion
最后还少一个括弧
------解决方案--------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
}去掉
protected void btnValidate_Click(Object sender,EventArgs e)
{
int i=userNameValidate();
}
///<summary>
///验证用户是否存在
///</summary>
public int userNameValidate()
{
SqlConnection conn=new SqlConnection(ConfigurationManager.Appsettings["DBConnectionString"]);
SqlCommand selecCmd =new SqlCommand("select * from Users where userId='"+txtName.Text.Trim()+"'",conn);
int i=0;
try{
conn.open();
SqlDataReader sdr = SelectCmd.ExecuteReader();
if (sdr.Read())
{
int i=1;
lblMessage.Text="此用户已存在,请输入其他用户名";
}
else{
lblMessage.Text="此用户名是可用的!";
}
}
catch(System.exception ee){
Response.write("<script language=javascript>alert('"+ee.Message.toString+"')</script>");

}
finally{
conn.Close;
}
}
}增加
------解决方案--------------------
public int userNameValidate() 
明显得函数体没有返回值么。。。