本文介绍了使用未分配的局部变量'mySqlCommand'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试应用dcuments但发生以下错误



  protected   void  Button1_Click( object  sender,EventArgs e)
{

string connStr = ConfigurationManager.ConnectionStrings [ mydms ]的ConnectionString。
SqlConnection mySQLconnection = new SqlConnection(connStr);
if (mySQLconnection.State == ConnectionState.Closed)
{
mySQLconnection.Open();
}
// DropDownList drdList;
SqlCommand mySqlCommand;


foreach (GridViewRow row in GrdFileApprove.Rows)
{

if (row.RowType == DataControlRowType.DataRow)
{
DropDownList DropDownListcontrol = row .FindControl( DropDownList4 as 下拉列表;

SqlCommand cmd = new SqlCommand( approved,mySQLconnection);

docc.approve(Convert.ToInt32(会话[ UserID] ),Convert.ToInt32(会话[ DocID]),Convert.ToInt32(Session [ ApproveID]),Convert.ToString(Session [ Login2]));


mySqlCommand.Parameters.Add( @ UserID ,SqlDbType.Int).Value = Convert.ToInt32(GrdFileApprove.DataKeys [row.RowIndex] [ UserID]);

mySqlCommand.Parameters.Add( @ DocID,SqlDbType.Int ).Value = Convert.ToInt32(GrdFileApprove.DataKeys [row.RowIndex] [ DocID]) ;

mySqlCommand.Parameters.Add( @ ApproveID,SqlDbType.Int ).Value = DropDownListcontrol.SelectedValue;

// docc.approve(Convert.ToInt32(Session [UserID])), Convert.ToInt32(Session [DocID]),Convert.ToInt32(Session [ApproveID]),Convert.ToString(Session [Login2]));

mySqlCommand .ExecuteNonQuery();
}
else
{
apfi.Text = 错误;
}


}


如果(mySQLconnection.State = = ConnectionState.Open)
{
mySQLconnection.Close();
}
}





此行错误



  mySqlCommand  .Parameters.Add(  @ UserID,SqlDbType.Int).Value = Convert.ToInt32(GrdFileApprove.DataKeys [row.RowIndex] [ 用户ID]); 
解决方案



i try to apprve dcuments but the following error occur

protected void Button1_Click(object sender, EventArgs e)
        {

            string connStr = ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
            SqlConnection mySQLconnection = new SqlConnection(connStr);
            if (mySQLconnection.State == ConnectionState.Closed)
            {
                mySQLconnection.Open();
            }
               // DropDownList drdList;
            SqlCommand mySqlCommand;


            foreach (GridViewRow row in GrdFileApprove.Rows)
            {

                if (row.RowType == DataControlRowType.DataRow)
                {
                    DropDownList DropDownListcontrol = row.FindControl("DropDownList4") as DropDownList;

                    SqlCommand cmd = new SqlCommand("approved", mySQLconnection);

                    docc.approve(Convert.ToInt32(Session["UserID"]), Convert.ToInt32(Session["DocID"]), Convert.ToInt32(Session["ApproveID"]), Convert.ToString(Session["Login2"]));


                    mySqlCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = Convert.ToInt32(GrdFileApprove.DataKeys[row.RowIndex]["UserID"]);

                    mySqlCommand.Parameters.Add("@DocID", SqlDbType.Int).Value = Convert.ToInt32(GrdFileApprove.DataKeys[row.RowIndex]["DocID"]);

                    mySqlCommand.Parameters.Add("@ApproveID", SqlDbType.Int).Value = DropDownListcontrol.SelectedValue;

                    //docc.approve(Convert.ToInt32(Session["UserID"]), Convert.ToInt32(Session["DocID"]), Convert.ToInt32(Session["ApproveID"]), Convert.ToString(Session["Login2"]));

                    mySqlCommand.ExecuteNonQuery();
                }
                else
                {
                    apfi.Text = "Error";
                }


            }


            if (mySQLconnection.State == ConnectionState.Open)
            {
                mySQLconnection.Close();
            }
        }



error in this line

mySqlCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = Convert.ToInt32(GrdFileApprove.DataKeys[row.RowIndex]["UserID"]);
解决方案



这篇关于使用未分配的局部变量'mySqlCommand'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-21 02:13
查看更多