[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1373
  • Last Modified:

ASP.NET C# ODBC Select query is returning truncated result string

Hello all,

I am trying to populate a drop down list with a database query in an ASP.NET project. My problem is that the result values from the query are being truncated at 15 characters, and I don't know why this would be.

I am using System.Data.ODBC.

I am creating my database connection using OdbcConnection("SYSTEM_DSN");
OdbcConnection cxconn = new OdbcConnection("DSN=SYSTEMDSN");

My query is in a string:
//build the select statement to get items to populate session drop-down
string ProgramQuery = "SELECT major_table.txt_adm from major_table where major_table.dept = 'EXCL' ";
ProgramQuery += "and major_table.web_display = 'Y' and major_table.inactive_date is NULL;";

And this is how I execute the query and populate my drop-down:
 OdbcCommand cxcommand = cxconn.CreateCommand();
            cxcommand.CommandText = ProgramQuery;

                OdbcDataReader dbreader = cxcommand.ExecuteReader();
                // rest of the code to process the result set
                int fCount = dbreader.FieldCount;
                while (dbreader.Read())
                    for (int i = 0; i < fCount; i++)
                        Response.Write(" " + dbreader.GetValue(i));



                //close the dbreader

                //bind the data on ddlSess and set the selected value by default to be the first one.
                ddlProg.SelectedIndex = 0;


The resulting values in the drop down list are truncated at 15 characters. So, "Business Administration" becomes "Business Admini". I am unable to figure out why this is the case. My database is an INFORMIX database and I have the system DSN created using the INFORMIX 3.80 32 BIT driver.

Any help would be really appreciated. Thanks for looking into this.

  • 2
  • 2
1 Solution
Todd GerbertIT ConsultantCommented:
I would guess simply that the drop down list isn't wide enough; the values are not being truncated, but all the characters cannot be shown. Is the width of the drop-down list explicity specified in the <asp:DropDownList> tag?
gcampbell1Author Commented:
Thanks for your reply.

No, the width is  not the issue. I tried to expand the dropdownlist width, and the values were still truncated. I don't think this is a problem with the drop down list because the "Response.Write" line in the for loop prints out the truncated value as well.

I am not sure if it is an OdbcDataReader issue or an informix driver issue, but those two would be my guesses as problem areas. I just don't know where to even start looking.
Todd GerbertIT ConsultantCommented:
I don't think I see anything in your code that would cause that behavior - is the column in the Informix database defined as 15 characters wide (the MS SQL equivelant of char(15))?
gcampbell1Author Commented:
Thanks, again, for the reply. The database was not the problem either (since the value is stored properly on the database end).

I realized the problem was the INFORMIX 3.80 driver for the System DSN. I tried using the 3.34 driver and the string is no longer getting truncated.


Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now