当前位置: 代码迷 >> ASP.NET >> 语法异常兄弟们帮帮忙
  详细解决方案

语法异常兄弟们帮帮忙

热度:8424   发布时间:2013-02-25 00:00:00.0
语法错误兄弟们帮帮忙
public class DataNew
{
public DataNew()
{

}
  string conSql = "server=.;database=sweet;uid=sa;pwd=111111";
  private SqlConnection sqlcon;
   
  public DataTable DataSelectNews()
  {
  string sql = "select nid,ntitle,ncontent,pubdate from news";
  sqlcon = new SqlConnection(conSql);
  SqlDataAdapter da = new SqlDataAdapter(sql,sqlcon);
  DataSet ds = new DataSet();
  da.Fill(ds,"news");
  DataTable dt = ds.Tables[0];
  return dt;
  }


  public DataTable DataShowNew( string sql)
  {
  string sql1 = "select ,ntitle,ncontent from news where nid="+sql;
   
  sqlcon = new SqlConnection(conSql);
  SqlDataAdapter da = new SqlDataAdapter(sql, sqlcon);
  DataSet ds = new DataSet();
  da.Fill(ds, "news");
  DataTable dt = ds.Tables[0];
  return dt;
   
  }
   
}

、、、、错误信息

行 42: SqlDataAdapter da = new SqlDataAdapter(sql, sqlcon);
行 43: DataSet ds = new DataSet();
行 44: da.Fill(ds, "news");
行 45: DataTable dt = ds.Tables[0];
行 46: return dt;
 

源文件: d:\TEST\SolutionTestWeb\Web\WebSweet\App_Code\DataNew.cs 行: 44 

堆栈跟踪: 


[SqlException (0x80131904): '2' 附近有语法错误。]
  System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +109
  System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +57
  System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +207
  System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2423
  System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
  System.Data.SqlClient.SqlDataReader.get_MetaData() +80
  System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +291
  System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +949
  System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +242
  System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +20
  System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +129
  System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +10
  System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
  System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +128
  System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +141
  System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +91
  DataNew.DataShowNew(String sql) in d:\TEST\SolutionTestWeb\Web\WebSweet\App_Code\DataNew.cs:44
  ContentNew.Page_Load(Object sender, EventArgs e) in d:\TEST\SolutionTestWeb\Web\WebSweet\ContentNew.aspx.cs:28
  System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
  相关解决方案