Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL syntax error

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());
   }
}
like image 943
G Gr Avatar asked Apr 21 '26 01:04

G Gr


1 Answers

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
like image 136
BoltClock Avatar answered Apr 22 '26 14:04

BoltClock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!