作新闻显示的页面,第 1 行: '=' 附近有语法错误。

fengliangcc 2007-05-26 07:56:50
这是我的链接数据库的源代码
<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();
}


行 21: ds = new DataSet();
行 22: SqlDataAdapter myCommand = new SqlDataAdapter(strCom,MyConnection);
行 23: myCommand.Fill(ds,"news");
行 24: dr = ds.Tables["news"].Rows[0];
行 25: strCon = "SELECT counter FROM news WHERE id = " + newsid;

...全文
701 31 打赏 收藏 转发到动态 举报
写回复
用AI写文章
31 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
好人+高手+
=楼上
sbqcel 2007-05-26
  • 打赏
  • 举报
回复
注意查收邮件,请及时回复我
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
fengliangcc@126.com
qq:267202229

谢谢了

今晚能给我答复么
sbqcel 2007-05-26
  • 打赏
  • 举报
回复
把你邮件地址留下....
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
麻烦 活死人 你了
别批评我了 汗阿
时间紧迫
没有时间le
希望你能帮忙
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
基础很差俄
现在是救急阿
时间很紧

用ASp.net1.0
很基础的代码,
帮帮忙吧
数据库:
news

news

datagrid控件  点击链接 绑定 detail.aspx? id={0}
detail.aspx 代码如下

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="detail.aspx.cs" Inherits="detail" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>新闻详细信息</title>
<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 = 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");
if (ds.Tables["news"].Rows.Count == 0)
return;
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();
}

</script>


<style type="text/css">
<!--
a {
font-size: 12px;
color: #333333;
}
a:visited {
color: #000000;
}
a:hover {
color: #C8180B;
}
.STYLE1 {font-size: 10px}
.STYLE3 {font-size: 12px}
.STYLE5 {
color: #EA0100;
font-weight: bold;
font-size: 18px;
}
.STYLE6 {font-weight: bold}
#Layer1 {
position:absolute;
left:249px;
top:-21px;
width:387px;
height:54px;
z-index:1;
}
.STYLE9 {color: #C53131}
.STYLE15 {color: #B51021}
.STYLE16 {font-family: "华文细黑"}
.STYLE17 {
color: #333333;
font-weight: bold;
}
.STYLE18 {font-family: "宋体"}
.STYLE19 {color: #FFFFFF}
.STYLE20 {font-size: 10px; color: #FFFFFF; }
body {
margin-top: 0cm;
background-image: url(%E5%9B%BE%E7%89%87+Flash/backgroun.gif);
}
.STYLE23 {font-family: "华文琥珀"; color: #CF0535;}
.STYLE24 {color: #F1F1F1}
.STYLE25 {
font-size: 18px;
font-family: "宋体";
font-weight: bold;
color: #282425;
}
.STYLE26 {color: #333333; }
.STYLE28 {
font-weight: bold;
color: #B51021;
font-size: 18px;
font-family: "华文琥珀";
}
body {
margin-left: 120px;
margin-top: 0px;
margin-right: 120px;
background-image: url(images/backgroun.gif);
}

-->


</style>


</head>
<body>

<center>




<table width="790" height="471" border="0" bgcolor="white">
<!--DWLayoutTable-->
<tr>
<td style="border-left-color: #ff0033; border-bottom-color: #ff0033; width: 192px; border-right-color: #ff0033; border-top: #ff0033 2px outset;" bgcolor="#f6f6f6" bordercolor="buttonface">
<span style="font-size: 10pt; border-bottom-color: #ff0033; border-top-color: #ff0033; border-bottom-style: inset; color: #4e4e4d;">
 <img align="middle" src="images/topleft.gif" style="font-size: 10pt; height: 17px" />公告栏</span></td>
<td valign="top" style="text-align: right; width: 509px; border-top: #ff0033 2px outset; vertical-align: top;" bgcolor="#f6f6f6" bordercolor="buttonface">
<span style="border-bottom-color: #ff0033; border-bottom-style: inset;">
<span
style="font-size: 10pt; border-bottom-color: #ff0033; border-bottom-style: inset; color: #4e4e4d;">
  <a href="javascript:window.print()">打印本页</a>
</span></span></td>
</tr>
<tr>
<td style="border-left-color: #ff0033; border-bottom-color: #ff0033; width: 192px; border-right-color: #ff0033; height: 130px; border-top: #ff0033 2px outset;"> <span style="font-size: 10pt"></span></td>
<td style="width: 509px; height: 130px; text-align: center; border-top: #ff0033 2px outset; vertical-align: top;">
<table>
<tr>
<td style="width: 728px; text-align: left; height: 20px;" align="center">
<%=dr["strBiaoti"] %>
</td></tr>
<tr>
<td style="height: 55px; width: 728px;">
<div> <hr size="1" width="80%" /><br /><%=dr["shijian"] %></div>
</td></tr>
<tr><td style="height: 40px; width: 728px;">
<%
if (dr["img"] != "")
{
Response.Write("<img src='" + dr["img"] + "' border='0' align='left' width='20%' height='70'>");
}%>
<br /><%=dr["neirong"] %>
</td></tr>

<tr><td style="width: 728px">
<br />
<span style="font-size: 10pt">文章出自:<%=dr["zhaizi"] %></span>
</td></tr>
</table>
<table>
<tr><td style="width: 428px; text-align: left; height: 13px;" align="center">
<span style="font-size: 10pt">
本条新闻被浏览了<%=dr["Counter"] %>次 </span>
c
</td>
<td style="height: 13px">
<p align="right"><a href="javascript:window.close()">关闭窗口</a></p>
</td></tr>
</table>
</td>
</tr>
</table>
</center>



</body>
</html>
sbqcel 2007-05-26
  • 打赏
  • 举报
回复
看了你的代码我真的不知道你要干嘛;
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");
if (ds.Tables["news"].Rows.Count == 0)
return;
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 ++;
//i准备干嘛也不知道
reader.Close();
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
活死人 

还是不会加 
sbqcel 2007-05-26
  • 打赏
  • 举报
回复
实在不知道你想做什么~~
建议你好好理理思路,明白自己要干什么,好好补补基础
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
还是这样:

<strong>未将对象引用设置到对象的实例。</strong>
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:


行 183: <tr>
行 184: <td style="width: 728px; text-align: left; height: 20px;" align="center">
行 185: <%=dr["biaoti"] %>
行 186: </td></tr>
行 187: <tr>

vfan2010 2007-05-26
  • 打赏
  • 举报
回复
SQL语句问题
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
我的代码这样的
怎么加阿 
求救
50分 
救人于水火 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>新闻详细信息</title>
<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");
if (ds.Tables["news"].Rows.Count == 0)
return;
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();

</script>


<style type="text/css">
<!--
a {
font-size: 12px;
color: #333333;
}
a:visited {
color: #000000;
}
a:hover {
color: #C8180B;
}
.STYLE1 {font-size: 10px}
.STYLE3 {font-size: 12px}
.STYLE5 {
color: #EA0100;
font-weight: bold;
font-size: 18px;
}
.STYLE6 {font-weight: bold}
#Layer1 {
position:absolute;
left:249px;
top:-21px;
width:387px;
height:54px;
z-index:1;
}
.STYLE9 {color: #C53131}
.STYLE15 {color: #B51021}
.STYLE16 {font-family: "华文细黑"}
.STYLE17 {
color: #333333;
font-weight: bold;
}
.STYLE18 {font-family: "宋体"}
.STYLE19 {color: #FFFFFF}
.STYLE20 {font-size: 10px; color: #FFFFFF; }
body {
margin-top: 0cm;
background-image: url(%E5%9B%BE%E7%89%87+Flash/backgroun.gif);
}
.STYLE23 {font-family: "华文琥珀"; color: #CF0535;}
.STYLE24 {color: #F1F1F1}
.STYLE25 {
font-size: 18px;
font-family: "宋体";
font-weight: bold;
color: #282425;
}
.STYLE26 {color: #333333; }
.STYLE28 {
font-weight: bold;
color: #B51021;
font-size: 18px;
font-family: "华文琥珀";
}
body {
margin-left: 120px;
margin-top: 0px;
margin-right: 120px;
background-image: url(images/backgroun.gif);
}

-->


</style>


</head>
<body>
sbqcel 2007-05-26
  • 打赏
  • 举报
回复
那就定义在函数体外吧,和你那几个变量放一起......
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
sbqcel(活死人) :

我前后台没有分开 、

直接在连接数据库的代码里写就可以吧?

不知道怎么写啊 
~~~
sbqcel 2007-05-26
  • 打赏
  • 举报
回复
不可以那样;你在后台代码里定义一个protected类型的string 变量
protected string strBiaoti ;
strBiaoti = dr["biaoti"].ToString();


页面里:<%=strBiaoti %>
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
谢谢楼上
又有 错误了 
%%%%%~~~~~

未将对象引用设置到对象的实例。
行 182: <td style="width: 728px; text-align: left; height: 20px;" align="center">
行 183: <%=dr["biaoti"] %>//加红
行 184: </td></tr>
行 185: <tr>

我在《body》里直接用dr[“”] 显示
这样不行么?
sbqcel 2007-05-26
  • 打赏
  • 举报
回复
if(ds.Tables["news"].Rows.Count == 0)
return;
dr = ds.Tables["news"].Rows[0];
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
按照zhuanshen712 的意见改了
又出现:错误
在位置 0 处没有任何行。


行 22: SqlDataAdapter myCommand = new SqlDataAdapter(strCom,MyConnection);
行 23: myCommand.Fill(ds,"news");
行 24: dr = ds.Tables["news"].Rows[0];
行 25: strCon = "SELECT counter FROM news WHERE id = " + int.Parse(newsid).ToString();
行 26: SqlCommand myCommand2 = new SqlCommand(strCon,MyConnection);


行 24: dr = ds.Tables["news"].Rows[0];  加红显示

是不是有进步了
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
id 也是 int型
急于求成了
5
fengliangcc 2007-05-26
  • 打赏
  • 举报
回复
库名 表名一样的
加载更多回复(11)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧