我是初学者,执行web连接数据库好,进行查找时候出现问题,大家帮忙看看。CSQL类代码using System;
using System.Data ;
using System.Data.SqlClient ;namespace WebApplicationWeb
{
/// <summary>
/// CSQL 的摘要说明。
/// 
/// </summary>
public class CSQL
{
public static string SConnStr;
protected SqlConnection myConnection;
protected SqlCommand myCommand;
protected SqlDataReader myDataReader;

public CSQL(string SDataSource,string SCatalog)
{
SConnStr="Data Source="+SDataSource+";Integrated Security=SSPI;Initial Catalog="+SCatalog;
} public void Connection()
{
myConnection = new SqlConnection (SConnStr);
}
public void Search(ref string SSql)
{
myConnection.Open ();
myCommand = new SqlCommand (SSql,myConnection);
}
~CSQL()
{
myConnection.Close ();
} }
public class Ccheck:CSQL
{
public Ccheck(string SDataSource,string SCatalog):base(SDataSource,SCatalog)
{
;
}
public bool Check()
{
myDataReader=myCommand.ExecuteReader();//<<<<<<出错<<<<<<<
if(!myDataReader.Read())//如果没有读到记录
return false;
else 
return true;
} }
}Web页实现登录验证。
private void LinkButton1_Click(object sender, System.EventArgs e)
{
string Ssql;
Ccheck CmyCheck=new Ccheck("localhost","user");
CmyCheck.Connection ();
Ssql="select * from user where username='"+username.Text+"' and password='"+password.Text +"'";
CmyCheck.Search(ref Ssql);
if (CmyCheck.Check())
Response.Redirect ("WebForm4.aspx");//验证通过跳转
else
Response.Write ("密码或用户名错误"); }编译通过,当按下按钮时出现错误。在关键字 'user' 附近有语法错误。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 在关键字 'user' 附近有语法错误。源错误: 
行 45:  public bool Check()
行 46:  {
行 47:  myDataReader=myCommand.ExecuteReader();
行 48:  if(!myDataReader.Read())//如果没有读到记录
行 49:  return false;
 源文件: c:\inetpub\wwwroot\webapplicationweb\csql.cs    行: 47 堆栈跟踪: 
[SqlException: 在关键字 'user' 附近有语法错误。]
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
   System.Data.SqlClient.SqlCommand.ExecuteReader()
   WebApplicationWeb.Ccheck.Check() in c:\inetpub\wwwroot\webapplicationweb\csql.cs:47
   WebApplicationWeb.WebForm1.LinkButton1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplicationweb\webform1.aspx.cs:72
   System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   System.Web.UI.Page.ProcessRequestMain()