为何总提示“用户代码未处理”的提示呢?谢谢!
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.ConnectionString["ConnectionSting"].Connectionstring;
如果你是AppSettings配置节,那么检查下配置节的name属性前后是否一致
ConnectionSting==============ConnectionString
[解决办法]
["ConnectionSting"]应该是这个参数的值没有获取到,空了~
这是个空引用的异常
[解决办法]
string ConString = ConfigurationManager.ConnectionStrings["OVERTIMEConnectionString"].ConnectionString;
[解决办法]
很明显你接收到的值为null啊·调试看看为什么呗