1

How to bind data from two tables.

tbl_user first name userid

tbl_usermessage userid timereceived msgid

How to display username and timereceived in datagrid

SELECT TimeReceived, FirstName FROM tbl_usermessage INNER JOIN tbl_user on tbl_usermessage.tbl_user_UserID = tbl_user.UserID WHERE tbl_message_MsgID = @Value1";

This is what I am trying i am getting syntax error. here Time received is from tbl_usermessage and firstname is from tbl_User and both table has userid

3 Answers 3

1

How about joining both tables on your sql query?

Sign up to request clarification or add additional context in comments.

Comments

0

You need to connect a SqlDataSource to your DataGrid by setting the SqlDataSource's DataSourceID property to the SqlDataSourceID. Set the SqlDataSource's SelectCommand property to the SQL required to get the items:

SelectCommand="SELECT tableone.username, tableone.userid, tabletwo.userid, tabletwo.timereceived
FROM tableone INNER JOIN tabletwo ON tableone.userid=tabletwo.userid"

And also set the ConnectionString property:

ConnectionString="<%$ ConnectionStrings:MyDatabaseConnectionString %>" >

1 Comment

SELECT TimeReceived, FirstName FROM tbl_usermessage INNER JOIN tbl_user on tbl_usermessage.tbl_user_UserID = tbl_user.UserID WHERE tbl_message_MsgID = @Value1"; This is what I am trying i am getting syntax error. here Time received is from tbl_usermessage and firstname is from tbl_User and both table has userid
0

You need to retrieve the data from your database with a SQL Query which JOINs the two tables on a column that is common to both:

Something along these lines:

SELECT
    userId, username, timereceived
FROM
    Table1 INNER JOIN Table2 ON Table1.userId = Table2.UserID

Here's an example for your reference.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.