0

protected void cmdLogin_Click(object sender, EventArgs e) {

    Class1.con = CreateConnection();
    string str = "SELECT Ad_Regid from Admin_Profile WHERE Ad_Regid LIKE @TempPasscode";
    cmd = new SqlCommand(str, Class1.con);
    if(Class1.con.State==ConnectionState.Closed)
        Class1.con.Open();
        cmd.Parameters.AddWithValue("@TempPasscode", txtcurrentpwd.Text.Trim());
        SqlDataReader dr = cmd.ExecuteReader();

        if (dr.Read())
        {
            if (dr[0].ToString() == txtcurrentpwd.Text)
        {
                using (cmd = new SqlCommand("_insertAdminLogin", Class1.con))
                if (Class1.con.State == ConnectionState.Closed)
                Class1.con.Open();
                cmd.CommandType = System.Data.CommandType.StoredProcedure ;
                cmd.Parameters.AddWithValue("@AdminType", ddltype.SelectedItem.Text);
                cmd.Parameters.AddWithValue("@AdminUsrname", txtuname.Text);
                cmd.Parameters.AddWithValue("@AdminPwd", txtconfirmpwd.Text);

                **using cmd.ExecuteNonQuery();**
         }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "Warning", "javascript:alert('Temporary Password Does not Match!');", true);
            }
         }
        Class1.con.Close();
}    

我正在尝试保存 3 个字段,但它显示有一个打开的数据阅读器“你应该关闭它”......但我使用 using 关键字进行相同的用途......

请帮忙!!

4

1 回答 1

0

在调用 cmd.ExecunoteNonQuery 之前,调用dr.Close();

于 2013-07-06T16:40:54.680 回答