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

出了两个问题,帮我看看吧
第一个:
public   partial   class   Image_TryNews2   :   System.Web.UI.Page
{
     
      public   DataSet   ds;
      public   DataRow   dr;
      public     String   newsid;
        private     void   Page_Load(object   sender,   EventArgs   e)
        {
                SqlConnection   MyConnection;    
String   ConnStr,strCon;  
newsid   =   Request.Params[ "ID "];  
MyConnection   =new   SqlConnection( "Initial   Catalog=sol;Data   Source=hnu-a4cafe281e0\\sqlexpress;Integrated   Security=SSPI; ");  
MyConnection.Open();  
String   strCom=   "SELECT   Title   ,FromTo   ,Content,Counter   ,Time   FROM   TableNews1   where   ID= "+newsid;  
ds=   new   DataSet();  
SqlDataAdapter   myCommand=new   SqlDataAdapter(strCom,MyConnection);  
myCommand.Fill(ds, "TableNews1 ");  
dr   =   ds.Tables[ "TableNews1 "].Rows[0];  
strCon   = "SELECT   Counter   FROM   TableNews1   WHERE   ID   =   ' "+newsid+ " ' ";  
SqlCommand   myCommand2   =   new   SqlCommand(strCon,   MyConnection);  
SqlDataReader   reader   =   myCommand2.ExecuteReader();  
reader.Read();  
int   i   =   reader.GetInt32(0);  
i++;  
reader.Close();  
strCon   = "UPDATE   TableNews1   SET   Counter   =   "+i.ToString()+ "   WHERE   (   ID=   "+newsid+ ") ";  
myCommand2.CommandText   =   strCon;  
myCommand2.ExecuteNonQuery();  
MyConnection.Close();  
}  
        }

报错:
'= '   附近有语法错误。  
说明:   执行当前   Web   请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。  

异常详细信息:   System.Data.SqlClient.SqlException:   '= '   附近有语法错误。

源错误:  


行   29:   ds=   new   DataSet();  
行   30:   SqlDataAdapter   myCommand=new   SqlDataAdapter(strCom,MyConnection);  
行   31:   myCommand.Fill(ds, "TableNews1 ");  
行   32:   dr   =   ds.Tables[ "TableNews1 "].Rows[0];  
行   33:   strCon   = "SELECT   Counter   FROM   TableNews1   WHERE   ID   =   ' "+newsid+ " ' ";  
 
第二个

        ConnStr   =   "   SET       IDENTITY_INSERT   sol.dbo.TableNews1   on;   insert   into   TableNews1(Title,Content,Time,Image,Counter)   VALUES( ' "   +   biaoti.Text   +   " ',   ' "   +   zhaizi.Text   +   " ', "   +   neirong2   +   " ',   ' "   +   now.ToString()   +   " ',   ' "   +   img.Text   + &n