By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,892 Members | 1,112 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,892 IT Pros & Developers. It's quick & easy.

Preserving column names in a data set

P: n/a
Hello

I'm filling a data set in C# from an SQL database and then binding
this to a repeater. I have an OnItemCreated method on this repeater
and I am trying to get the value in a column called "ServiceFK".
However, it appears I can only use an index rather than a column name
which I am loathe to do. Can anyone help? Here's a sample of my code:

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection connection = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["Connection"].ToString());
SqlCommand command = connection.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "sp_GetAllServices";

connection.Open();
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "Service");

ServicesRepeater.DataSource = dataSet.Tables["Service"];
ServicesRepeater.DataBind();
connection.Close();
}
protected void ServicesRepeater_OnItemCreated(object Sender,
RepeaterItemEventArgs e)
{
SqlConnection connection = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["wealdConnection"].ToString());
SqlCommand command = connection.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "sp_GetFeatures";
command.Parameters.AddWithValue("@serviceID",
DataBinder.Eval(e.Item.DataItem, "serviceID")); // fails here with
serviceID
....
....
....
....
}

Any help greatly appreciated!

Thanks, Mark
Jul 3 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Actually, it doesn't even work with an index! How do I get the value
at all??

On Jul 3, 1:45*pm, mark.norg...@gmail.com wrote:
Hello

I'm filling a data set in C# from an SQL database and then binding
this to a repeater. I have an OnItemCreated method on this repeater
and I am trying to get the value in a column called "ServiceFK".
However, it appears I can only use an index rather than a column name
which I am loathe to do. Can anyone help? Here's a sample of my code:

* * protected void Page_Load(object sender, EventArgs e)
* * {
* * * * SqlConnection connection = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["Connection"].ToString*());
* * * * SqlCommand command = connection.CreateCommand();
* * * * command.CommandType = CommandType.StoredProcedure;
* * * * command.CommandText = "sp_GetAllServices";

* * * * connection.Open();
* * * * SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
* * * * DataSet dataSet = new DataSet();
* * * * dataAdapter.Fill(dataSet, "Service");

* * * * ServicesRepeater.DataSource = dataSet.Tables["Service"];
* * * * ServicesRepeater.DataBind();
* * * * connection.Close();
* * }

* * protected void ServicesRepeater_OnItemCreated(object Sender,
RepeaterItemEventArgs e)
* * {
* * * * SqlConnection connection = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["wealdConnection"].ToS*tring());
* * * * SqlCommand command = connection.CreateCommand();
* * * * command.CommandType = CommandType.StoredProcedure;
* * * * command.CommandText = "sp_GetFeatures";
* * * * command.Parameters.AddWithValue("@serviceID",
DataBinder.Eval(e.Item.DataItem, "serviceID")); // fails here with
serviceID
...
...
...
...

}

Any help greatly appreciated!

Thanks, Mark
Jul 3 '08 #2

P: n/a
On Jul 3, 2:17*pm, mark.norg...@gmail.com wrote:
Actually, it doesn't even work with an index! How do I get the value
at all??

On Jul 3, 1:45*pm, mark.norg...@gmail.com wrote:
Hello
I'm filling a data set in C# from an SQL database and then binding
this to a repeater. I have an OnItemCreated method on this repeater
and I am trying to get the value in a column called "ServiceFK".
However, it appears I can only use an index rather than a column name
which I am loathe to do. Can anyone help? Here's a sample of my code:
* * protected void Page_Load(object sender, EventArgs e)
* * {
* * * * SqlConnection connection = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["Connection"].ToString**());
* * * * SqlCommand command = connection.CreateCommand();
* * * * command.CommandType = CommandType.StoredProcedure;
* * * * command.CommandText = "sp_GetAllServices";
* * * * connection.Open();
* * * * SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
* * * * DataSet dataSet = new DataSet();
* * * * dataAdapter.Fill(dataSet, "Service");
* * * * ServicesRepeater.DataSource = dataSet.Tables["Service"];
* * * * ServicesRepeater.DataBind();
* * * * connection.Close();
* * }
* * protected void ServicesRepeater_OnItemCreated(object Sender,
RepeaterItemEventArgs e)
* * {
* * * * SqlConnection connection = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["wealdConnection"]..ToS**tring());
* * * * SqlCommand command = connection.CreateCommand();
* * * * command.CommandType = CommandType.StoredProcedure;
* * * * command.CommandText = "sp_GetFeatures";
* * * * command.Parameters.AddWithValue("@serviceID",
DataBinder.Eval(e.Item.DataItem, "serviceID")); // fails here with
serviceID
...
...
...
...
}
Any help greatly appreciated!
Thanks, Mark- Hide quoted text -

- Show quoted text -
Doh! Was being an idiot. I simply need:

command.Parameters.AddWithValue("@serviceID",
((DataRowView)e.Item.DataItem)["ServiceID"]);
Jul 3 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.