我刚开始自学.net。 任务是一个月里做一个简单的微博系统出来。 我现在找了一些书来看。然后书里的源代码有几处错误,不会修改。望指点一下。谢谢using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;namespace blog_garden
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection myConn;
int topic_id;
string topic_title;
string blog_name;
protected void Page_Load(object sender, EventArgs e)
{
string blog_dns = ConfigurationSettings.AppSettings["conn"];
myConn = new SqlConnection(blog_dns); topic_title = Request.QueryString["topic_title"] == null ? "" : Request.QueryString["topic_title"].ToString();
string sql_string = "update topic set topic_hit_num=topic_hit_num+1 where topic_id=" + topic_title; SqlCommand myCmd2 = new SqlCommand(sql_string, myConn);
myConn.Open();
myCmd2.ExecuteNonQuery(); myConn.Close(); sql_string = "select topic_id,topic_author,topic_class,topic_title,topic_date,topic_review_num,topic_hit_num,topic_content from topic where topic_id=" + topic_title; SqlDataAdapter myCmd = new SqlDataAdapter(sql_string, myConn);
DataSet myds = new DataSet();
myCmd.Fill(myds, "文章列表"); DataList1.DataSource = new DataView(myds.Tables[0]);
DataList1.DataBind(); topic_id = (int)myds.Tables[0].Rows[0][0];
sql_string = "select * from review where topic_id=" + topic_id.ToString();
SqlDataAdapter myCmd1 = new SqlDataAdapter(sql_string, myConn);
DataSet myds1 = new DataSet();
myCmd1.Fill(myds1, "评论列表"); DataList2.DataSource = new DataView(myds1.Tables[0]);
DataList2.DataBind(); if (Session["UserName"] == null)
{
TextBox2.Text = "游客";
DataList1.Controls[0].Controls[9].Visible = false;
DataList1.Controls[0].Controls[7].Visible = false;
for (int i = 0; i < DataList2.Controls.Count; i++)
{
DataList2.Controls[i].Controls[9].Visible = false; if (myds1.Tables[0].Rows[i][4].ToString() == "游客")
DataList2.Controls[i].Controls[3].Visible = false;
}
}
else
{
sql_string = "select name from blog_user where nick_name='" + Session["UserName"].ToString() + "'";
SqlDataAdapter myCmd3 = new SqlDataAdapter(sql_string, myConn);
DataSet myds2 = new DataSet();
myCmd3.Fill(myds2, "用户列表");
TextBox2.Text = myds2.Tables[0].Rows[0][0].ToString();
if (TextBox2.Text == myds.Tables[0].Rows[0][1].ToString())
{
blog_name = TextBox2.Text;
Button bb = (Button)DataList1.Items[0].FindControl("Button3");
bb.Attributes.Add("OnClick", "ff();"); for (int j = 0; j < DataList2.Controls.Count; j++)
{
bb = (Button)DataList2.Items[j].FindControl("Button5");
bb.Attributes.Add("OnClick", "tt();");
}
}
else
{
DataList1.Controls[0].Controls[9].Visible = false;
DataList1.Controls[0].Controls[7].Visible = false;
for (int i = 0; i < DataList2.Controls.Count; i++)
{
DataList2.Controls[i].Controls[9].Visible = false; if (myds1.Tables[0].Rows[i][4].ToString() == "游客")
DataList2.Controls[i].Controls[3].Visible = false;
}
}
}
}
protected void Button3_Click(object sender, EventArgs e)
{ }
protected void Button4_Click(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text.Trim() != "" && TextBox3.Text.Trim() != "")
{
string sql_string = "update topic set topic_review_num=topic_review_num+1 where topic_id=" + topic_title; SqlCommand myCmd2 = new SqlCommand(sql_string, myConn);
myConn.Open();
myCmd2.ExecuteNonQuery();
myConn.Close(); sql_string = "insert into review (topic_id,review_title,review_author,review_content,review_date) values (" + topic_id.ToString() + ",'" + TextBox1.Text.Trim() + "','" + TextBox2.Text.Trim() + "','" + TextBox3.Text.Trim() + "', getdate())"; SqlCommand myCmd = new SqlCommand(sql_string, myConn);
myConn.Open();
myCmd.ExecuteNonQuery();
myConn.Close(); this.Server.Transfer("topic.aspx?topic_title=" + topic_title);
}
else
{
Response.Write("<script>alert('请将评论填写完整');</script>");
}
}
protected void Button2_Click(object sender, EventArgs e)
{ }
}
}第一处加红那里, 错误时 “=”号附近有语法错误;
第二处加红那里, 未将对象引用到实例。 该如何改。 然后我该如何有针对性地学习呢?
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;namespace blog_garden
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection myConn;
int topic_id;
string topic_title;
string blog_name;
protected void Page_Load(object sender, EventArgs e)
{
string blog_dns = ConfigurationSettings.AppSettings["conn"];
myConn = new SqlConnection(blog_dns); topic_title = Request.QueryString["topic_title"] == null ? "" : Request.QueryString["topic_title"].ToString();
string sql_string = "update topic set topic_hit_num=topic_hit_num+1 where topic_id=" + topic_title; SqlCommand myCmd2 = new SqlCommand(sql_string, myConn);
myConn.Open();
myCmd2.ExecuteNonQuery(); myConn.Close(); sql_string = "select topic_id,topic_author,topic_class,topic_title,topic_date,topic_review_num,topic_hit_num,topic_content from topic where topic_id=" + topic_title; SqlDataAdapter myCmd = new SqlDataAdapter(sql_string, myConn);
DataSet myds = new DataSet();
myCmd.Fill(myds, "文章列表"); DataList1.DataSource = new DataView(myds.Tables[0]);
DataList1.DataBind(); topic_id = (int)myds.Tables[0].Rows[0][0];
sql_string = "select * from review where topic_id=" + topic_id.ToString();
SqlDataAdapter myCmd1 = new SqlDataAdapter(sql_string, myConn);
DataSet myds1 = new DataSet();
myCmd1.Fill(myds1, "评论列表"); DataList2.DataSource = new DataView(myds1.Tables[0]);
DataList2.DataBind(); if (Session["UserName"] == null)
{
TextBox2.Text = "游客";
DataList1.Controls[0].Controls[9].Visible = false;
DataList1.Controls[0].Controls[7].Visible = false;
for (int i = 0; i < DataList2.Controls.Count; i++)
{
DataList2.Controls[i].Controls[9].Visible = false; if (myds1.Tables[0].Rows[i][4].ToString() == "游客")
DataList2.Controls[i].Controls[3].Visible = false;
}
}
else
{
sql_string = "select name from blog_user where nick_name='" + Session["UserName"].ToString() + "'";
SqlDataAdapter myCmd3 = new SqlDataAdapter(sql_string, myConn);
DataSet myds2 = new DataSet();
myCmd3.Fill(myds2, "用户列表");
TextBox2.Text = myds2.Tables[0].Rows[0][0].ToString();
if (TextBox2.Text == myds.Tables[0].Rows[0][1].ToString())
{
blog_name = TextBox2.Text;
Button bb = (Button)DataList1.Items[0].FindControl("Button3");
bb.Attributes.Add("OnClick", "ff();"); for (int j = 0; j < DataList2.Controls.Count; j++)
{
bb = (Button)DataList2.Items[j].FindControl("Button5");
bb.Attributes.Add("OnClick", "tt();");
}
}
else
{
DataList1.Controls[0].Controls[9].Visible = false;
DataList1.Controls[0].Controls[7].Visible = false;
for (int i = 0; i < DataList2.Controls.Count; i++)
{
DataList2.Controls[i].Controls[9].Visible = false; if (myds1.Tables[0].Rows[i][4].ToString() == "游客")
DataList2.Controls[i].Controls[3].Visible = false;
}
}
}
}
protected void Button3_Click(object sender, EventArgs e)
{ }
protected void Button4_Click(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text.Trim() != "" && TextBox3.Text.Trim() != "")
{
string sql_string = "update topic set topic_review_num=topic_review_num+1 where topic_id=" + topic_title; SqlCommand myCmd2 = new SqlCommand(sql_string, myConn);
myConn.Open();
myCmd2.ExecuteNonQuery();
myConn.Close(); sql_string = "insert into review (topic_id,review_title,review_author,review_content,review_date) values (" + topic_id.ToString() + ",'" + TextBox1.Text.Trim() + "','" + TextBox2.Text.Trim() + "','" + TextBox3.Text.Trim() + "', getdate())"; SqlCommand myCmd = new SqlCommand(sql_string, myConn);
myConn.Open();
myCmd.ExecuteNonQuery();
myConn.Close(); this.Server.Transfer("topic.aspx?topic_title=" + topic_title);
}
else
{
Response.Write("<script>alert('请将评论填写完整');</script>");
}
}
protected void Button2_Click(object sender, EventArgs e)
{ }
}
}第一处加红那里, 错误时 “=”号附近有语法错误;
第二处加红那里, 未将对象引用到实例。 该如何改。 然后我该如何有针对性地学习呢?
解决方案 »
- 在做一个项目很多页面都要用到同样的方法,现在想把这个方法写在一个公共类里面做公共方法,请问应该用静态类静态方法还是用非静态类静态方法?
- 为何无法使用DateAndTime.DateDiff方法
- C# 操作 excel 不连续单元格
- 求助:关于数据库访问的问题
- 读取数据库数据问题
- 谁看过北大青鸟的ASP.NET视频
- C#中,string str = null 与 string str =""有什么区别
- C#里面有关事件托管
- 关于xml的问题 ,为什么Value 总是空呢?
- 请教socket接受数据,异步处理的问题
- xxx.aspx?xx=xxx从url传递过来的参数如何获取并使用呢?
- 请问如何用c#直接发送soap请求
查询分析中执行看看
Button bb = (Button)DataList1.Items[0].FindControl("Button3");
if(bb!=null){}
第二个冒失没有找到你的哪个ff()
string sql_string = "update topic set topic_hit_num=topic_hit_num+1 where topic_id='" + topic_title+"'";
--估计就这个title是字符串
--改成这样试试