Click here to Skip to main content
14,219,244 members
Rate this:
Please Sign up or sign in to vote.
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?

/// 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);
}
}
CHill60 9-Jul-14 15:14pm
   
That's the code that calls the stored procedure - the change is likely to be needed within dbo.upCmp_Select_LU - what is in there?
sankarsan parida 9-Jul-14 22:32pm
   
where r u binding counterparty combobox? and what is ur storeprocedure with mention your problem

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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:
// 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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100