locked
Returning more than one parameter from SP RRS feed

  • Question

  • User1863994004 posted

    Hi. I'm trying to get more than one parameter from stored procedure, but somethings is not right. It works with one OUTPUT parameter. In the end of the loop every variables is empty, but values come from the database.

            protected void Button_Check_AsDc_Click(object sender, EventArgs e)
            {
                SqlConnection SqlConn = new SqlConnection("Data Source = VESOORG; Initial Catalog = LIBRARY; Integrated Security = True ");
                SqlCommand SqlComm = new SqlCommand("sp_check_member", SqlConn);
                SqlComm.CommandType = CommandType.StoredProcedure;
                int error_number = 0;
                string Type = "";
                string FirstName = "";
                string MiddleName = "";
                string LastName = "";           
                string Faculty = "";
                string Speciallity = "";
                string Course = "";
    
                try
                {
                    using (SqlConn)
                    {
                        SqlConn.Open();
    
                        SqlComm.Parameters.Add("@IDN", SqlDbType.BigInt).Value = TextBox_IDN_AsDc.Text;
    
                        SqlComm.Parameters.Add("@error_number", SqlDbType.Int).Direction = ParameterDirection.Output;
    
                        SqlComm.Parameters.Add("@Type", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
                        SqlComm.Parameters.Add("@FirstName", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
                        SqlComm.Parameters.Add("@MiddleName", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
                        SqlComm.Parameters.Add("@LastName", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
                        SqlComm.Parameters.Add("@Faculty", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
                        SqlComm.Parameters.Add("@Speciallity", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
                        SqlComm.Parameters.Add("@Course", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
    
                        SqlComm.ExecuteNonQuery();
    
                        error_number = (int)SqlComm.Parameters["@error_number"].Value;
    
                        Type = Convert.ToString(SqlComm.Parameters["@Type"].Value);
                        FirstName = Convert.ToString(SqlComm.Parameters["@FirstName"].Value);
                        MiddleName = Convert.ToString(SqlComm.Parameters["@MiddleName"].Value);
                        LastName = Convert.ToString(SqlComm.Parameters["@LastName"].Value);
                        Faculty = Convert.ToString(SqlComm.Parameters["@Faculty"].Value);
                        Speciallity = Convert.ToString(SqlComm.Parameters["@Speciallity"].Value);
                        Course = Convert.ToString(SqlComm.Parameters["@Course"].Value);
    
    .......................
    .......................
    .......................



    Thursday, July 26, 2012 4:43 PM

Answers

  • User-287491473 posted

    I think you have a typo.  Try this on your converts:

                        Type = Convert.ToString(SqlComm.Parameters["@Type"].Value); 
                        FirstName = Convert.ToString(SqlComm.Parameters["@FirstName"].Value); 
                        MiddleName = Convert.ToString(SqlComm.Parameters["@MiddleName"].Value); 
                        LastName = Convert.ToString(SqlComm.Parameters["@LastName"].Value); 
                        Faculty = Convert.ToString(SqlComm.Parameters["@Faculty"].Value); 
                        Speciallity = Convert.ToString(SqlComm.Parameters["@Speciallity"].Value); 
                        Course = Convert.ToString(SqlComm.Parameters["@Course"].Value); 
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 26, 2012 4:50 PM

All replies

  • User-287491473 posted

    I think you have a typo.  Try this on your converts:

                        Type = Convert.ToString(SqlComm.Parameters["@Type"].Value); 
                        FirstName = Convert.ToString(SqlComm.Parameters["@FirstName"].Value); 
                        MiddleName = Convert.ToString(SqlComm.Parameters["@MiddleName"].Value); 
                        LastName = Convert.ToString(SqlComm.Parameters["@LastName"].Value); 
                        Faculty = Convert.ToString(SqlComm.Parameters["@Faculty"].Value); 
                        Speciallity = Convert.ToString(SqlComm.Parameters["@Speciallity"].Value); 
                        Course = Convert.ToString(SqlComm.Parameters["@Course"].Value); 
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 26, 2012 4:50 PM
  • User1863994004 posted

    Yes i did it. I edit my post. Now they are empty. Strange...

    Thursday, July 26, 2012 4:58 PM
  • User1863994004 posted

    I'm sorry. I have yo double check it. It's all working fine. 10x for the fast answer :)

    Thursday, July 26, 2012 5:05 PM