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
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