[RESOLVED] [2.0] SqlDataSource question
How do I access the data in a SqlDataSource? Here's what I'm trying to do:
Code:
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["id"];
if (id == null)
return;
string sql = "SELECT o.obj_id, o.description, o.desc_long, o.file_name, " +
"o.file_path, o.t_image, o.sim, o.file_size, o.downloads, " +
"o.obj_size, s.sim_name, s.sim_image FROM objects AS o " +
"INNER JOIN sims AS s ON s.sim_id = o.sim " +
"WHERE o.obj_id ='" + id + "'";
SqlDataSource1.ConnectionString =
@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\stuff.mdf;Integrated Security=True;User Instance=True";
SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.Text;
SqlDataSource1.SelectCommand = sql;
SqlDataSource1.DataBind();
this.Title = ""; // <- want this to be o.description
}
The SQL will return only one row, but I'm not sure how to access the individual items in the SqlDataSource in order to set the page title to the description. Any suggestions?
Re: [2.0] SqlDataSource question
If you're trying to access the data directly in code, don't use a datasource, use a dataset instead. Create a dataadapter, pass it your connection string information and SQL statement, and then call the fill() method of the dataadapter, passing it a dataset. You can then access all the data in a dataset...
ds.Tables[0].Rows[0]["ColumnName"].ToString();
Re: [2.0] SqlDataSource question
Quote:
Originally Posted by mendhak
If you're trying to access the data directly in code, don't use a datasource, use a dataset instead.
Yeah, silly me actually thought I could access data from a data source... :rolleyes:
Thanks for the info.