作新闻显示的页面,第 1 行: '=' 附近有语法错误。
这是我的链接数据库的源代码
<script language= "C# " runat= "server ">
DataSet ds;
DataRow dr;
String newsid;
void Page_load(Object sender, EventArgs e)
{
SqlConnection MyConnection;
String ConnStr, strCon;
newsid = Request.Params[ "id "];
MyConnection = new SqlConnection( "server=localhost;database=news;uid=sa;pwd= ' ' ");
MyConnection.Open();
String strCom = "SELECT biaoti,zhaizi,neirong,img,counter,shijian FROM news where id= " + newsid;
ds = new DataSet();
SqlDataAdapter myCommand = new SqlDataAdapter(strCom,MyConnection);
myCommand.Fill(ds, "news ");
dr = ds.Tables[ "news "].Rows[0];
strCon = "SELECT counter FROM news 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 news SET counter= " + i.ToString() + " WHERE(id= " + newsid+ ") ";
myCommand2.CommandText = strCon;
myCommand2.ExecuteNonQuery();
MyConnection.Close();
}