Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've a combobox 'counterparty' and a table 'commodity trades'. In the table , i've two columns 'counterparty' and associated 'contract status' column to that counterparty. There are 6 different contract statuses. Now , I want my counterparty combobox to dsiplay only those values which are associated with two contract statuses. How can I do this?

C#
/// Connects to database and gets counterparty data
/// 
/// <param name="gasDay"></param>
/// 
public DataTable GetCounterpartyInfos(DateTime gasDay)
{
    try
    {
      DataTable dt = new DataTable("Counterparty");
     
      using (var context = ConnectionManager.GetManager(Database.Gms))
      {
        using (SqlCommand fetchCommand =
          context.Connection.CreateCommand("dbo.upCmp_Select_LU"))
        {
          fetchCommand.Parameters.Add("@GasDay", 
             SqlDbType.DateTime).Value = gasDay;
          fetchCommand.Parameters.Add("@DBFunction", 
             SqlDbType.VarChar).Value = "Nominations";
     
          SqlDataAdapter ta = new SqlDataAdapter(fetchCommand);
          ta.Fill(dt);
        }
      }
      return dt;
    }
    catch (Exception ex)
    {
      throw FoundationAgent.CreateFoundationExceptionWrapper(
      new FoundationException("Exception is in GetCounterpartyInfos()", ex), ex);
    }
}
Posted
Updated 9-Jul-14 15:43pm
v2
Comments
CHill60 9-Jul-14 9:31am    
How are you populating the comboBox?
Member 10935161 9-Jul-14 11:02am    
I'm using a stored procedure for populating it
Member 10935161 9-Jul-14 11:17am    
hi , can I have your mail ID for a better accessibility. I need a solution for this problem
CHill60 9-Jul-14 12:33pm    
No to email, that's not how this forum works.
What is the code in the stored procedure?
Member 10935161 9-Jul-14 13:52pm    
/// Connects to database and gets counterparty data
///
/// <param name="gasDay"></param>
/// <returns>
public DataTable GetCounterpartyInfos(DateTime gasDay)
{
try
{
DataTable dt = new DataTable("Counterparty");

using (var context = ConnectionManager<sqlconnection>.GetManager(Database.Gms))
{
using (SqlCommand fetchCommand = context.Connection.CreateCommand("dbo.upCmp_Select_LU"))
{
fetchCommand.Parameters.Add("@GasDay", SqlDbType.DateTime).Value = gasDay;
fetchCommand.Parameters.Add("@DBFunction", SqlDbType.VarChar).Value = "Nominations";

SqlDataAdapter ta = new SqlDataAdapter(fetchCommand);
ta.Fill(dt);
}
}
return dt;
}
catch (Exception ex)
{
throw FoundationAgent.CreateFoundationExceptionWrapper(
new FoundationException("Exception is in GetCounterpartyInfos()", ex), ex);
}
}

1 solution

I think what you want to do is to filer the rows in the DataTable depending on the value of one column.
You don't make it easy to interpret your wish, though. You really need to provide more information.
I am just guessing now that this is what you want to do.

You can do this in c# code:
C#
// Create a table with two columns
DataTable dt = new DataTable("Food");
dt.Columns.Add("Name");
dt.Columns.Add("Type");

dt.Rows.Add("Apple", "Fruit");
dt.Rows.Add("Carrot", "Vegetable");
dt.Rows.Add("Pear", "Fruit");
dt.Rows.Add("Cucumber", "Vegetable");
dt.Rows.Add("Tomato", "Fruit");
dt.Rows.Add("Broccoli", "Vegetable");

// Create a DataView
DataView dv = new DataView(dt);

// Filter out the fruits
dv.RowFilter = "Type = 'Fruit'";


Then use the DataView as the DataSource for your ComboBox.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900