Please help- me
using System;
using System.Data;
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.SqlClient;
public partial class get : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session.Count == 0)
Response.Redirect("Default.aspx");
else
{
if
(!IsPostBack)
{
string strconn = "server=.;database=Northwind; user id=sa;pwd=";
PostID= Request["PostID"] ;
}
string strconn = "server=.;database=Northwind; user id=sa;pwd=";
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = strconn;
BindData();
}
}
private void BindData()
{
string selCmd1 = "select * from Ex09_GuestBook where PostID="+PostID;
SqlDataAdapter da1=new SqlDataAdapter(selCmd1,myConnection);
string selCmd2 = "select * from Ex09_GuestBook where ParentID= " + 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][5].ToString();
HyperLink1.Text=ds.Tables["host"].Rows[0][3].ToString();
HyperLink1.NavigateUrl="userInfo.aspx?UserName="+HyperLink1.Text;
DataList1.DataSource=ds;
DataList1.DataMember="guest";
DataList1.DataBind();
this.DataBind();
myConnection.Close();
}
protected void Button3_Click(object sender, EventArgs e)
{
string strconn = "server=.;database=Northwind; user id=sa;pwd=";
string Name = Session["username"].ToString();
string insCmd = "insert Ex09_GuestBook values(" + PostID + ",getdate(),'" + Name + "','','" + TextBox1.Text + "')";
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = strconn;
SqlCommand myCmd = new SqlCommand(insCmd, myConnection);
myCmd.Connection.Open();
myCmd.ExecuteNonQuery();
myCmd.Connection.Close();
myConnection.Close();
BindData();
TextBox1.Text = "";
}
protected void Button4_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
}
}
I do not know why it alawys occur this
error
CS0103: there is no"PostID"
行 35:
行 36:
行 37: PostID= Request["PostID"] ;
行 38:
行 39:
You a reading the value fromRequest["PostID"] which is null where you have set the value and also check for null
like
if( Request["PostID"] != null )
PostID= Request["PostID"] ;
No comments:
Post a Comment