ComboBox using a select statemet

  • Thread starter Thread starter nbohana
  • Start date Start date
N

nbohana

I am trying to use the following select statement to put records into a
combobox, when I run the application I only get one record, I should get
three records. Please help me!!

try
{
strSQL = "SELECT [company-code], [bid-number] FROM
[job-setup] Where [company-code] = " + PrepareStr(ccode);

con = new
SqlConnection("Server=icc-server;DataBase=Construction;Integrated
Security=SSPI;Persist Security Info=False");

comm = new SqlCommand(strSQL, con);

if (con.State != ConnectionState.Open)
{
con.Open();
}

conrdr = comm.ExecuteReader();

if (conrdr.Read())
{
Bidnumber.Text = conrdr["bid-number"].ToString();
}

con.Close();

}
 
nbohana said:
I am trying to use the following select statement to put records into a
combobox, when I run the application I only get one record, I should get
three records. Please help me!!

try
{
strSQL = "SELECT [company-code], [bid-number] FROM
[job-setup] Where [company-code] = " + PrepareStr(ccode);

con = new
SqlConnection("Server=icc-server;DataBase=Construction;Integrated
Security=SSPI;Persist Security Info=False");

comm = new SqlCommand(strSQL, con);

if (con.State != ConnectionState.Open)
{
con.Open();
}

conrdr = comm.ExecuteReader();

if (conrdr.Read())
{
Bidnumber.Text = conrdr["bid-number"].ToString();
}

con.Close();

}

If Bidnumber is the combobox, then you should be filling the items in
the combobox, not the text property. You also are not looping on the
reader, that is, you only execute one read. You will want to loop on
the reader as long as .Read is true.
 
Thank you Mike!!!

Family Tree Mike said:
nbohana said:
I am trying to use the following select statement to put records into a
combobox, when I run the application I only get one record, I should get
three records. Please help me!!

try
{
strSQL = "SELECT [company-code], [bid-number] FROM
[job-setup] Where [company-code] = " + PrepareStr(ccode);

con = new
SqlConnection("Server=icc-server;DataBase=Construction;Integrated
Security=SSPI;Persist Security Info=False");

comm = new SqlCommand(strSQL, con);

if (con.State != ConnectionState.Open)
{
con.Open();
}

conrdr = comm.ExecuteReader();

if (conrdr.Read())
{
Bidnumber.Text = conrdr["bid-number"].ToString();
}

con.Close();

}

If Bidnumber is the combobox, then you should be filling the items in
the combobox, not the text property. You also are not looping on the
reader, that is, you only execute one read. You will want to loop on
the reader as long as .Read is true.
 
Mike I am having a little trouble trying to code a loop, will you help me.
This is what I have tried to code. I cannot find and example. In this case
the while statement does not except '=='. Please help

Norm

try
{
strSQL = "SELECT [company-code], [bid-number] FROM
[job-setup] Where [company-code] = " + PrepareStr(ccode);

con = new
SqlConnection("Server=icc-server;DataBase=Construction;Integrated
Security=SSPI;Persist Security Info=False");

comm = new SqlCommand(strSQL, con);

if (con.State != ConnectionState.Open)
{
con.Open();
}

conrdr = comm.ExecuteReader();

do
{
if (conrdr.Read())
{
cbBidnumber.Text = conrdr["bid-number"].ToString();
}
} while (conrdr == true);

con.Close();

Family Tree Mike said:
nbohana said:
I am trying to use the following select statement to put records into a
combobox, when I run the application I only get one record, I should get
three records. Please help me!!

try
{
strSQL = "SELECT [company-code], [bid-number] FROM
[job-setup] Where [company-code] = " + PrepareStr(ccode);

con = new
SqlConnection("Server=icc-server;DataBase=Construction;Integrated
Security=SSPI;Persist Security Info=False");

comm = new SqlCommand(strSQL, con);

if (con.State != ConnectionState.Open)
{
con.Open();
}

conrdr = comm.ExecuteReader();

if (conrdr.Read())
{
Bidnumber.Text = conrdr["bid-number"].ToString();
}

con.Close();

}

If Bidnumber is the combobox, then you should be filling the items in
the combobox, not the text property. You also are not looping on the
reader, that is, you only execute one read. You will want to loop on
the reader as long as .Read is true.
 
Thanks Mike I solved my loop problem. What I have not solved is how to get
the data to go into the cells of the combobox. everything only goes into the
first cell. I tried indexing. Please would you explain what I must do to make
this work. Thanks for your help

Norm

Mike I am having a little trouble trying to code a loop, will you help me.
This is what I have tried to code. I cannot find and example. In this case
the while statement does not except '=='. Please help

Norm

try
{
strSQL = "SELECT [company-code], [bid-number] FROM
[job-setup] Where [company-code] = " + PrepareStr(ccode);

con = new
SqlConnection("Server=icc-server;DataBase=Construction;Integrated
Security=SSPI;Persist Security Info=False");

comm = new SqlCommand(strSQL, con);

if (con.State != ConnectionState.Open)
{
con.Open();
}

conrdr = comm.ExecuteReader();

do
{
if (conrdr.Read())
{
cbBidnumber.Text = conrdr["bid-number"].ToString();
}
} while (conrdr == true);

con.Close();

Family Tree Mike said:
nbohana said:
I am trying to use the following select statement to put records into a
combobox, when I run the application I only get one record, I should get
three records. Please help me!!

try
{
strSQL = "SELECT [company-code], [bid-number] FROM
[job-setup] Where [company-code] = " + PrepareStr(ccode);

con = new
SqlConnection("Server=icc-server;DataBase=Construction;Integrated
Security=SSPI;Persist Security Info=False");

comm = new SqlCommand(strSQL, con);

if (con.State != ConnectionState.Open)
{
con.Open();
}

conrdr = comm.ExecuteReader();

if (conrdr.Read())
{
Bidnumber.Text = conrdr["bid-number"].ToString();
}

con.Close();

}

If Bidnumber is the combobox, then you should be filling the items in
the combobox, not the text property. You also are not looping on the
reader, that is, you only execute one read. You will want to loop on
the reader as long as .Read is true.
 
Back
Top