Preserving column names in a data set

M

mark.norgate

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.ConnectionStrings["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.ConnectionStrings["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
 
M

mark.norgate

Actually, it doesn't even work with an index! How do I get the value
at all??
 
M

mark.norgate

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

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.ConnectionStrings["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.ConnectionStrings["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"]);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top