首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

System.InvalidOperationException: ConnectionString 属性尚未初始化。

2014-01-28 
------解决方法--------------------------------------------------------public partial class Ex09_03 :

------解决方法--------------------------------------------------------

public partial class Ex09_03 : System.Web.UI.Page
{
protected SqlConnection myConnection = new SqlConnection();
private void BindData()
{
string selCmd = "select * from Ex09_GuestBook where(ParentID=0) order by PostTime DESC ";
SqlDataAdapter da = new SqlDataAdapter(selCmd, myConnection);
DataSet ds = new DataSet();
da.Fill(ds, "word ");
DataGrid1.DataSource = ds.Tables[ "word "].DefaultView;
DataGrid1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session.Count == 0)
{
Response.Redirect( "Ex09_01.aspx ");
}
else if (!IsPostBack)
{
Label1.Text = "欢迎 " + Session[ "username "].ToString();
string strConn = "server=Localhost;uid=sa;pwd=sa;database=Aspnet ";
myConnection.ConnectionString = strConn;
BindData();
}

}

protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{