How To Put A Concatenated Data From Database To A Label
My table goes like this: | ID | FNAME | LNAME | My code goes like this: cmd.CommandText = 'SELECT * FROM members WHERE ID = '' & Label18.Text & ''' dreader = cmd
Solution 1:
cmd.CommandText = "SELECT CONCAT(fname,' ',lname) FROM members WHERE ID = '" & Label18.Text & "';"Label3.Text = cmd.ExecuteScalar
Note : This makes sense when the select returns a single Cell value
ExecuteScalar() in SqlCommand Object is used for get a single value from Database after its execution. It executes SQL statements or Stored Procedure and returned a scalar value on first column of first row in the Result Set. If the Result Set contains more than one columns or rows , it takes only the first column of first row, all other values will ignore. If the Result Set is empty it will return a Null reference.
Post a Comment for "How To Put A Concatenated Data From Database To A Label"