|
-
Dec 11th, 2007, 04:14 PM
#1
Thread Starter
Lively Member
[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?
-
Dec 12th, 2007, 08:17 AM
#2
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();
-
Dec 12th, 2007, 08:47 AM
#3
Thread Starter
Lively Member
Re: [2.0] SqlDataSource question
 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...
Thanks for the info.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|