c# - Populate array with numbers from database -


I am trying to extract the best way to populate an array with numerical values ​​extracted from the database. This is such a function that I have so far installed:

  protected int [] GetBoxes () {int [] box; String Query = "UIDbox = Add Product Length" Baird_Ground_Boxes_Products "to the product ID; (using SqlConnection cn = New SqlConnection (AbleConnectionStr)) {SqlCommand cmd = new SqlCommand (query, cn); Cmd.CommandType = CommandType.Text; cn.Open (); (IDTA Reader Reader = CMD.xTextReader) {if (reader.Read ()) {if (reader ["length"]. ToString ()! = "") { // Generate array with length values}}}} Return boxes;}   

There is never a set of values ​​that can be returned (3 may be, Can be 2 I am confused about how to populate the array, as if I am making it very difficult or something, any suggestions will be useful!

At first sight, you may have multiple rows from your query. / P>

  Select a different length than the product Baird_Ground_Boxes_ProductsUIDbox = Join the product ID   

Therefore, you can read all your rows with a W .

  var length = new list & lt; String & gt; (); If (reader.HasRows) while (reader.Read ()) length. Add (reader.GetString (0)); Return length .oir ();   

And I wonder if your field length is actually a string, maybe you should consider using an integer, because the length is usually the numbers If this is the case, then make a change in the direction of GetString method GetInt32 , and change your type list.

  var length = new list & lt; Integer & gt; (); lengths.Add (reader.GetInt32 (0));    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -