Question

So far i have tried following:

        odbccmd1 = new OdbcCommand("SELECT DISTINCT JCDISTRIBTUION FROM MST WHERE  JOB="+lbljob.text , odbccon);
    odbccon.Open();
    OdbcDataReader ddl = odbccmd1.ExecuteReader();
    DropDownList ddll = new DropDownList();
    ddll.DataSource = ddl;
    ddll.DataBind();

or this

        using (OdbcDataReader CC1 = odbccmd1.ExecuteReader();
    {
        ddlCostC.DataSource = CC1;
        ddlCostC.DataBind();
        CC1.Close();
        ddlCostC.Focus();
    }

After many tries, i get following error:

Data conversion or data mapping error.

All im trying to achieve is, when i select something from dropdownlist and click on "Fetch" button, i would like it to go and fetch codes that are associated with that job and dump them into another dropdownlist.

But every time i have been getting that error. So i am not sure what i am doing wrong.

Appreciate it.

Was it helpful?

Solution

try with single quotes for job, assume you have varchar column

"SELECT DISTINCT JCDISTRIBTUION FROM MST WHERE  JOB='111111'"

without quotes you consider job as number type.

UPDATE:

with Text of text box

 odbccmd1 = new OdbcCommand("SELECT DISTINCT JCDISTRIBTUION FROM MST WHERE  JOB='"+lbljob.Text +"'", odbccon);

above will work, but you better use parameters like below

 odbccmd1 = new OdbcCommand("SELECT DISTINCT JCDISTRIBTUION FROM MST WHERE  JOB=?", odbccon);
 odbccmd1.Parameters.AddWithValue("job", lbljob.Text);

OTHER TIPS

I think you are missing lines similar to these:

ddll.DataTextField = "JCDISTRIBTUION ";
ddll.DataValueField = "JCDISTRIBTUION ";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top