调试了头都大了,总是这个问题,具体代码是这样的
[CODE]public class Comm1
{
public SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["labConnectionString"].ConnectionString);
public Comm1()
{
}
public void ENQ(string str)
{
SqlCommand myCommand = new SqlCommand(str, myConnection);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
return;
}
public string EXS(string str1)
{
SqlCommand myCommand1 = new SqlCommand(str1, myConnection);
myCommand1.Connection.Open();
string myex = myCommand1.ExecuteScalar().ToString();
myConnection.Close();
return(myex);
}
public void dg_Bind(string strCmd, DataGrid DataGrid1)
{
SqlDataAdapter adp = new SqlDataAdapter(strCmd, myConnection);
DataSet ds = new DataSet();
adp.Fill(ds);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
public void dr_Bind(string strCmd, DropDownList dr)
{
SqlDataAdapter adp = new SqlDataAdapter(strCmd, myConnection);
DataSet ds = new DataSet();
adp.Fill(ds);
dr.DataSource = ds;
return;
}
}[/CODE][CODE]public class drp_dmg
{
public Comm1 co_class;
public drp_dmg()
{
Comm1 co_class = new Comm1();
}
public void dept(DropDownList drp)
{
string str_dept = "select * from lab_dept";
co_class.dr_Bind(str_dept, drp);/
/未将对象引用设置到对象的实例 drp.DataBind();
}
public void major(DropDownList drp1)
{
string str_major = "select * from lab_major";
co_class.dr_Bind(str_major, drp1);
drp1.DataBind();
}
public void grade(DropDownList drp2)
{
string str_grade = "select * from lab_grade";
co_class.dr_Bind(str_grade, drp2);
drp2.DataBind();
}
public void teacher(DropDownList drp3)
{
string str_tea = "select * from lab_users where user_flag=2";
co_class.dr_Bind(str_tea,drp3);
drp3.DataBind();
}
}[/CODE]
页面的代码
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "" || TextBox2.Text == "")
{
Response.Write("<script defer>alert('请每项都输入!');</script>");
}
else
{
string strCmd = "select user_name from lab_users where user_ID like '" + TextBox1.Text + "'and password like '" + TextBox2.Text + "'";
Comm1 name_com = new Comm1();
string username = name_com.EXS(strCmd);
if (username != null)
{
banduan(username); //这段调试没问题
}
else//这段调试就会出现问题,出错就跳到类Comm1那了 {
{
Response.Write("<script defer>alert('密码不正确!');</script>");
TextBox1.Text = " ";
TextBox2.Text = " ";
}
}
}
[此贴子已经被作者于2007-4-22 20:03:17编辑过]