日期:2014-05-17  浏览次数:20490 次

语法错误兄弟们帮帮忙
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.DataSh