nice_candy 0 Newbie Poster

hi,

i have created a web form that input data from user and insert it into the mysql database by calling stored procedures butt i am facing the following error

" Exception during execution of 'p_AddUser': Invalid attempt to access a field before calling Read() ".

plz help me how can i resolve this error.

the code i am using is as follows:

        MySqlConnection sqlConn = new MySqlConnection(objdb.ConnString);
        MySqlCommand sqlCMD = new MySqlCommand("p_AddUser", sqlConn);
        sqlCMD.CommandType = CommandType.StoredProcedure;

        sqlCMD.Parameters.Add(new MySqlParameter("pgroup_id", objuser.usergroup));
        sqlCMD.Parameters.Add(new MySqlParameter("username", objuser.username));
        sqlCMD.Parameters.Add(new MySqlParameter("ppassword", objuser.pwd));
        sqlCMD.Parameters.Add(new MySqlParameter("pfirstname", objuser.fname));
        sqlCMD.Parameters.Add(new MySqlParameter("Plastname", objuser.lname));
        sqlCMD.Parameters.Add(new MySqlParameter("Pemail", objuser.email));
        sqlCMD.Parameters.Add(new MySqlParameter("Pstatus", objuser.status));
        try
        {
            sqlCMD.Connection.Open();
            [COLOR="Red"]int rows = sqlCMD.ExecuteNonQuery();[/COLOR]
            sqlConn.Close();
            return 1;
        }
        catch (Exception) {
            return 0;
        }

The error comes in the line with RED font.

thank and Best Regards,
Nice Candy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.