Hi I have two tables User and Pictures im trying to pull the pathname from my pictures table (userid=1) is the same in both related with pk, but Im unsure how to select firstname etc from user table and select picturepath from pictures table?
Im also wondering if the img path will be set correctly if i use the commented out line?
OdbcCommand cmd = new OdbcCommand("SELECT User.FirstName, User.SecondName, User.Aboutme, User.DOB, Pictures.picturepath FROM User LEFT JOIN Pictures ON User.UserID = Pictures.UserID WHERE User.UserID=1", cn);
OdbcDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Name.Text = String.Format("{0} {1}", reader.GetString(0), reader.GetString(1));
Aboutme.Text = String.Format("{0}", reader.GetString(2));
Age.Text = String.Format("{0}", reader.GetString(3));
Image1.ImageUrl = String.Format("{0}", reader.GetString(4));
}
}
}
To fetch data from two related tables in one query you can use a JOIN:
Then, yes, you can uncomment that last line.