Click here to Skip to main content
16,021,294 members

Comments by jmpapa (Top 16 by date)

jmpapa 25-Feb-13 9:26am View    
finally, I made it! I used this code:

MySqlConnection sqlcon = new MySqlConnection(strConnString);
sqlcon.Open();
string sqlcmd = "select CONCAT(firstname, ' (' ,lastname,')') AS mixname from userdbase";
da = new MySqlDataAdapter(sqlcmd,sqlcon);
dt.Clear();
da.Fill(dt);
if (dt.Rows.Count > 0)
{

ListBox1.DataSource = dt;
ListBox1.DataTextField = "mixname";
ListBox1.DataBind();
}

It's a combination of your given code and my previous code. Thank you very much for your help and patience.
jmpapa 25-Feb-13 7:34am View    
it's just the same with the code you posted above. The error is in this:

ListBox1.DataSource = dt;
ListBox1.DataTextField = "lastname";
ListBox1.DataBind();

I've also tried to use "firstname" in exchange to lastname, but still got the same error.
jmpapa 25-Feb-13 7:03am View    
Got this error:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'lastname'.
jmpapa 25-Feb-13 7:02am View    
got this error:
Incorrect parameter count in the call to native function 'ISNULL'
jmpapa 25-Feb-13 6:01am View    
Thank you Shubh! I applied your code in mine. And I came up with this:

sqlcon.Open();
string str = "select CONCAT(firstname, ' (' ,lastname,')') AS mixname from userdbase";
da = new MySqlDataAdapter(str, sqlcon);
DataSet ds = new DataSet();
da.TableMappings.Add("table", "empdependentd");
da.Fill(ds, "empdependents");
this.ListBox1.DataSource = this.ds;
this.ListBox1.DataTextField = "empdependents.mixname ";
this.ListBox1.DataValueField = "empdependents.mixname";
sqlcon.Close();
da.Dispose();

However, there's an error with this line:
this.ListBox1.DataSource = this.ds;
in the ds to be specific. What may caused this?