Hello I think im messing up my sql syntax, I cant seem to output firstname and second name to my label in asp.net
Table User has an entry UserID=1 and I would like to output the name of that entry into my label:
{
OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};
Server=localhost;
Database=gymwebsite;
User=a;
Password=b;");
cn.Open();
OdbcCommand cmd = new OdbcCommand("SELECT (FirstName, SecondName)
FROM User
WHERE UserID = 1", cn);
OdbcDataReader reader = cmd.ExecuteReader();
while (reader.Read()) {
Name.Text = (reader[1].ToString());
}
}
Remove the brackets from the SELECT field list:
SELECT FirstName, SecondName FROM User WHERE UserID=1
Or if you are trying to concatenate both fields into a single string:
SELECT CONCAT(FirstName, ' ', SecondName) FROM User WHERE UserID=1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With