Im attempting to grab something from the query. Im gettign a sintax error. It consists of an image title Then i wish to display that on my small page.

This is exactly what im doing how do you do that properly.


<asp:Image ID="Img1" ImageUrl="pathToPicture" runat="server" />


Picture DLtestPicture = new Picture();
DataTable DTTestPicture = DLtestPicture.GetRandomPicture();
String pathToPicture = DTTestPicture.Rows(0).Item("PicLoc").ToString();

You should utilize indexers rather:

String pathToPicture = DTTestPicture.Rows[0]["PicLoc"].ToString();

Alternatively - and preferrably, IMO - change GetRandomPicture to come back a strongly-typed value as opposed to a DataTable. It might a minimum of just return just one DataRow clearly, instead of coming back a table.

if (DTTestPicture.Rows.Count >= 0) 
  string pathToPicture= Convert.ToString(DTTestPicture.Rows[0]["PicLoc"]);

take a look


It's not a C# syntax. use [] around the host to () for containers/ Index based object.

Correct Syntax:


Around the host to toString() use Convert.ToString() for to prevent null value exception.