上午的问题 下午继续等 BBS回复问题
还是老问题 没有错误 好像数据不输出using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace liuyanban
{
/// <summary>
/// huifu 的摘要说明。
/// </summary>
public class huifu : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.DataList DataList1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label3;
protected SqlConnection myconnection=new SqlConnection();
private void Page_Load(object sender, System.EventArgs e)
{
if (Session.Count==0)
Response.Redirect("denglu.aspx");
else
{
if(!IsPostBack)
{postid=Request["postid"];
}
myconnection.ConnectionString="server=deant;uid=sa;pwd=sa;database=bbs";
BindData();
}
}
private void BindData()
{string selcmd1="select * from guestbook where postid="+postid;
SqlDataAdapter da1=new SqlDataAdapter(selcmd1,myconnection);
string selcmd2="select * from guestbook where postid="+postid;
SqlDataAdapter da2=new SqlDataAdapter(selcmd2,myconnection);
DataSet ds=new DataSet();
da1.Fill(ds,"host");
da2.Fill(ds,"guest");
Label1.Text=ds.Tables["host"].Rows[0][4].ToString();
int recount=ds.Tables["guest"].Rows.Count;
Label2.Text=recount.ToString();
Label3.Text=ds.Tables["host"].Rows[0][2].ToString();
Label4.Text=ds.Tables["host"].Rows[0][4].ToString();
HyperLink1.Text=ds.Tables["host"].Rows[0][3].ToString();
HyperLink1.NavigateUrl="liuyanzhe.aspx?username="+HyperLink1.Text;
DataList1.DataSource=ds;
DataList1.DataMember="guest";
DataList1.DataBind();
this.DataBind();
myconnection.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataList1.SelectedIndexChanged += new System.EventHandler(this.DataList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button2_Click(object sender, System.EventArgs e)
{
string name=Session["username"].ToString();
string inscmd="insert guestbook values("+postid+",gerdate(),'"+name+"','','"+Textbox2.Text+"')";
SqlCommand mycmd=new SqlCommand(inscmd,myconnection);
mycmd.Connection.Open();
mycmd.ExecuteNonQuery();
mycmd.Connection.Close();
BindData();
TextBox1.Text="";
}
private void Button1_Click(object sender, System.EventArgs e)
{
TextBox1.Text="";
}
}
}
--------------------编程问答--------------------
private void BindData()--------------------编程问答-------------------- 大概是什么错误你也说下啊,弄这一坨代码谁有闲心看 --------------------编程问答-------------------- 搞个代码 都没说错误哪个知道你的错! --------------------编程问答-------------------- 你都没有 Open() --------------------编程问答-------------------- 对啊 有可能啊 你的数据源都没有打开 哪有数据啊 --------------------编程问答-------------------- 在Fill前输入一句:myconnection.Open(); --------------------编程问答--------------------
{
myconnection.Open();
.......
myconnection.Close();
}
方法中没有打开数据源myconnection.Open();
试下看能不能出数据
补充:.NET技术 , ASP.NET