using (SqlConnection connection = new SqlConnection(DataHelper.ConnectionString))
        {
            using (SqlDataAdapter Adapter = new SqlDataAdapter())
            {

                try
                {
                    Adapter.InsertCommand.Connection.Open();

                    Adapter.InsertCommand = new SqlCommand("Sample", connection);
                    Adapter.InsertCommand.CommandType = CommandType.StoredProcedure;

                    Adapter.InsertCommand.Parameters.AddWithValue("@reqno", "emid");
                    Adapter.InsertCommand.Parameters.AddWithValue("@vouno", "emname");

                    Adapter.InsertCommand.ExecuteNonQuery();
                   
                }
                catch (Exception aa)
                {
                    MessageBox.Show("x " + aa);
                }
[B] Adapter.InsertCommand.Connection.Close();[/B] // It Shows error in here
            }

This error occurs, if the object which you are referring is Null. So, modify your last code block to:

catch (Exception aa)
{
    MessageBox.Show("x " + aa);
}
finally
{
    if (Adapter.InsertCommand.Connection != null)
        Adapter.InsertCommand.Connection.Close();
}
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.