ComboBox using a select statemet

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();

}
 
F

Family Tree Mike

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.
 
N

nbohana

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.
 
N

nbicc

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.
 
N

nbohana

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top