为何总提示“用户代码未处理”的提示呢?谢谢!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.AppSettings["ConnectionSting"].ToString();
SqlConnection sqlConn;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
public void Bind()
{
sqlConn = new SqlConnection(connStr);
sqlConn.Open();
string sqlstr = "select * from PAIGONGDAN";
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlConn);
DataSet myds = new DataSet();
myda.Fill(myds, "PAIGONGDAN");
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] {"AutoID"};
GridView1.DataBind();
sqlConn.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
------解决方案-------------------- 把web.config,也发出来。。
------解决方案--------------------AppSetting[...] 结果为 null。
------解决方案--------------------这个错误不叫代码未处理,而是空引用,也就是说,你这句代码获取的那个值为null
------解决方案--------------------你Web.config文件中配置的是ConnectionString配置节吧,那你程序中应该也是使用ConnectionString,而不是AppSettings
string connStr = ConfigurationManager.AppSettings["ConnectionSting"].ToString();
==============》更改成
string connStr = ConfigurationManager.ConnectionStr