473,322 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Preserving column names in a data set

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
2 1343
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joe Gazda | last post by:
I'm a relative newbie to PHP, but have been able to put together some PHP code to generate a CSV/XLS file from a Query result. Now, I would like to include custom column names instead of the MySQL...
1
by: noor | last post by:
Hi I have been working since 2 days to device a method to export sql table into csv format. I have tried using bcp with format option to keep the column names but I'm unable to transfer the file...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
1
by: Larry Bird | last post by:
I've created a AlertDataClass below within the class I have tables and column that I've create. In the AlertDataAccess class I'm trying to insert data into my tables. AlertDataAccess is a Module...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.