Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8001677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:08:54+00:00 2026-06-04T16:08:54+00:00

for (int i = 0; i < final_query.Length; i++) { con.Open(); SqlCommand cmd=new SqlCommand(SELECT

  • 0
for (int i = 0; i < final_query.Length; i++)
{
   con.Open();

   SqlCommand cmd=new SqlCommand("SELECT * fROM TableFFF WHERE Data="+final_query[i]);

   SqlDataReader rdr = cmd.ExecuteReader();

   while (rdr.Read())
   {
      string PatientName = (string)rdr[" Data "];
   }
}

I got that error

ExecuteReader: Connection property has not been initialized.

on this line

SqlDataReader rdr = cmd.ExecuteReader();

How can i fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:08:55+00:00Added an answer on June 4, 2026 at 4:08 pm

    You need to pass the Connection to the SqlCommand

    SqlCommand cmd=new SqlCommand("SELECT * fROM TableFFF WHERE Data="+final_query[i], con); 
    

    But there are other errors:

    • The call to con.Open() should be outside of the For loop
    • Use and reuse Parameters, not string concatenation

      con.Open();   
      SqlCommand cmd=new SqlCommand("SELECT * fROM TableFFF WHERE Data=@data", con);   
      cmd.Parameters.AddWithValue("@data", 0); // Supposing final_query[i] is an Int32
      for (int i = 0; i < final_query.Length; i++)   
      {   
          cmd.Parameters["@data"].Value = final_query[i];   
          SqlDataReader rdr = cmd.ExecuteReader();   
          while (rdr.Read())   
          {   
              string PatientName = (string)rdr[" Data "];   
          }   
      }
      

    And it is still not clear what you are supposing to do with the PatientName after the first round

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

int bufferlength = 12488; int pointer = 1; int offset = 0; int length
int length = strlen(src); char *structSpace = malloc(sizeof(String) + length + 1); String *string
I'm getting an NullPointerException when i'm trying to get data from my SQLiteDatabase in
I have this JDBC SQL query: select * from table where TX_DATE = {d
SELECT * FROM [productDetail] WHERE Price BETWEEN 0 AND 2000 OR Price BETWEEN 2000
Say I have a class: public class R { public static final int _1st
I have a JUnit test class in which I have several static final int
HashMap internally has its own static final variables for its working. static final int
int somefunction(bool a) { try { if(a) throw Error(msg); return 2; } catch (Error
int main() { int var = 0;; // Typo which compiles just fine }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.