locked
Error - Fill: SelectCommand.Connection property has not been initialized. RRS feed

  • Question

  • User-1499457942 posted

    Hi

    SqlCommand sqlCommand0 = new SqlCommand();
    
    
                            if (string.IsNullOrEmpty(dt.Rows[i]["Name"].ToString()) && !string.IsNullOrEmpty(dt.Rows[i]["Department"].ToString()))
                                {
                                    if (!string.IsNullOrEmpty(m_Criteria))
                                    {
                                        sqlCommand0.Connection = con;
                                        sqlCommand0.CommandText = ("Select * from [Data] where Department = @Department and " + m_Criteria);
                                    }
                                    else
                                    {
                                        sqlCommand0.Connection = con;
                                       sqlCommand0.CommandText = ("Select * from [Data] where Department = @Department ");
                                    }
                                    sqlCommand0.Parameters.AddWithValue("@Department", dt.Rows[i]["Department"].ToString());
                                    
                                }
                                SqlDataAdapter ad0 = new SqlDataAdapter(sqlCommand0);
                                DataTable dt0 = new DataTable();
                                ad0.Fill(dt0);

    Thanks

    Tuesday, August 28, 2018 2:39 PM

Answers

  • User-1499457942 posted

    Resolved . Logic Issue

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 28, 2018 2:53 PM