locked
Concat two columns and display it in grid view in mysql RRS feed

  • Question

  • User233888746 posted
            "SELECT UserID, FirstName, LastName, Email, CompanyName, Created, CreatedBy FROM tbl_user WHERE 
    tbl_organisation_OrganisationID = @Value1 order by UserID desc";

    using (DataServer server = new DataServer())
    {
    MySqlParameter[] param = new MySqlParameter[1];

    param[0] = new MySqlParameter("@value1", MySqlDbType.Int32);
    param[0].Value = newOrgID;
    command.Parameters.AddWithValue("@Value1", newOrgID);
    ds = server.ExecuteQuery(CommandType.Text, MysqlStatement, param);
    }

    UserTable.DataSource = ds;
    UserTable.DataBind();
    }

    The above one works perfectly, but when I concat first name and last name i am getting error. Whats wrong with the query.

    "SELECT UserID, Concat(FirstName,', ',LastName) as Name, Email, CompanyName, Created, CreatedBy
     FROM tbl_user WHERE tbl_organisation_OrganisationID = @Value1 order by UserID desc";

    Error is get is
    A field or property with the name 'FirstName' was not found on the selected data source.
    Wednesday, September 14, 2011 9:20 AM

Answers

  • User567269486 posted

    you need to remove Firstname and lastname boundfield or whatever you are using and use "Name" as the datafield according to the query.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 14, 2011 9:50 AM

All replies

  • User-674102814 posted
    try this

    "SELECT UserID, (FirstName +' '+ LastName) as Name, Email, CompanyName, Created, CreatedBy FROM tbl_user WHERE 
    tbl_organisation_OrganisationID = @Value1 order by UserID desc";

    it will work
    Wednesday, September 14, 2011 9:28 AM
  • User233888746 posted

    I get the same error

    A field or property with the name 'FirstName' was not found on the selected data source.

    Wednesday, September 14, 2011 9:45 AM
  • User567269486 posted

    you need to remove Firstname and lastname boundfield or whatever you are using and use "Name" as the datafield according to the query.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 14, 2011 9:50 AM