行 94: using (SqlDataAdapter da = new SqlDataAdapter(sql1, sqlCnn))
string str = ConfigurationManager.ConnectionStrings["2013ConnectionString"].ConnectionString;
using (SqlConnection sqlCnn = new SqlConnection(str))
{
string Conn4 = ConfigurationManager.ConnectionStrings["2013ConnectionString"].ToString();
SqlConnection myCon4 = new SqlConnection(Conn4); string cmdtext3 = "select * from luser where and lusername='" + Session["adminName"] + "'";
SqlCommand mycmd3 = new SqlCommand(cmdtext3, myCon4);
myCon4.Open();
SqlDataReader mydr3 = mycmd3.ExecuteReader(); if (mydr3.Read())
{ string sel08 = mydr3["l08"].ToString();
string sel09 = mydr3["l09"].ToString();
if (sel08 == "0")
{
string sql1 = "select id,kc_max,kc_week,kc_num,kc_js,kc_name,kc_type from xbkc_course where kc_grade='1' and kc_week = '8' order by id asc"; }
if (sel09 == "0")
{
string sql1 = "select id,kc_max,kc_week,kc_num,kc_js,kc_name,kc_type from xbkc_course where kc_grade='1' and kc_week = '9' order by id asc"; }
using (SqlDataAdapter da = new SqlDataAdapter(sql1, sqlCnn))
{
DataSet ds = new DataSet();
da.Fill(ds);
this.Repeater1.DataSource = ds;
this.Repeater1.DataBind();
}
}
mydr3.Close();
myCon4.Close();
}
string sql1 =
}
sql1的作用域在那对花括号内。你的情况sql1要写在括号外面。 string sql1;
if (sel08 == "0")
{
sql1 = "select id,kc_max,kc_week,kc_num,kc_js,kc_name,kc_type from xbkc_course where kc_grade='1' and kc_week = '8' order by id asc";
}
if (sel09 == "0")
{
sql1 = "select id,kc_max,kc_week,kc_num,kc_js,kc_name,kc_type from xbkc_course where kc_grade='1' and kc_week = '9' order by id asc";
}
CS0165: 使用了未赋值的局部变量“sql1”
string sql1="";,谢谢帅哥
CommandText 属性尚未初始化
行 97: da.Fill(ds);
using (SqlConnection sqlCnn = new SqlConnection(str))
{
string Conn4 = ConfigurationManager.ConnectionStrings["2013ConnectionString"].ToString();
SqlConnection myCon4 = new SqlConnection(Conn4);
myCon4.Open();
string cmdtext3 = "select * from luser where lusername='" + Session["adminName"] + "'";
SqlCommand mycmd3 = new SqlCommand(cmdtext3, myCon4);
SqlDataReader mydr3 = mycmd3.ExecuteReader(); if (mydr3.Read())
{ string sel08 = mydr3["l08"].ToString();
string sel09 = mydr3["l09"].ToString(); string sql1="";
if (sel08 == "0")
{
sql1 = "select id,kc_max,kc_week,kc_num,kc_js,kc_name,kc_type from xbkc_course where kc_grade='1' and kc_week = '8' order by id asc"; }
if (sel09 == "0")
{
sql1 = "select id,kc_max,kc_week,kc_num,kc_js,kc_name,kc_type from xbkc_course where kc_grade='1' and kc_week = '9' order by id asc"; }
using (SqlDataAdapter da = new SqlDataAdapter(sql1, sqlCnn))
{
DataSet ds = new DataSet();
da.Fill(ds);
this.Repeater1.DataSource = ds;
this.Repeater1.DataBind();
}
}
mydr3.Close();
myCon4.Close();
}