Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am using list-view that has it column form two different db tables .Here is my code that i am trying :
try
{
   String Query = "select id,Code,Description,Rate,Bottles,Supply,Empty,Amount,Received,
        Customer_New.Opening_Date,Customer_New.Clients_Title,Customer_New.Cust_Id 
         from (Items INNER JOIN Customer_New on Customer_New.Cust_Id=Items.Cust_Id)
                ,Customer_New";
    SQLiteDataAdapter  dba = new SQLiteDataAdapter(Query, GlobalVars.conn);
    DataSet testDs = new DataSet();
    dba.Fill(testDs, "Items");    //error
    dba.Fill(testDs, "Customer_New");   //error
    DataTable dt = testDs.Tables[0];
    this.lvcmodify.DataContext = testDs.Tables[0].DefaultView;
    lvcmodify.ItemsSource = dt.DefaultView;
    testDs.Dispose();
    dba.Dispose();
    dt.Dispose();
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}

Does anyone knows how i can accomplish this functionality in list view ? .Please help me to correct this code.Thanks
Posted
Updated 27-Nov-13 23:22pm
v2
Comments
Maciej Los 28-Nov-13 2:45am    
I'm bit confused...
Does the question is: How to join two tables? or How to display data on a listview?
Could you be more specific? Please, describe your problem.
Member 8840306 28-Nov-13 5:30am    
now see my improved question . i have one list view whose column are made from two tables .How i can use this command for two tables as it is useable only once for single list-view: dba.Fill(testDs, "Items"); //error
dba.Fill(testDs, "Customer_New"); //error
Maciej Los 28-Nov-13 8:34am    
Nothing informative ;(
You did not specify what kind of error do you get and its description. You need to read about how to use SQLiteDataAdapter class.
Please, see my answer.
bbirajdar 28-Nov-13 3:16am    
Use the dataTable.Merge() method
Member 8840306 28-Nov-13 5:27am    
Please help me how to implement dataTable.Merge() method...Explain how to it use for given scenario

1 solution

Please, read my comments first.

There aren't 2 tables! There are 2 source tables and one destination table only, because you joined them with INNER JOIN statement.
SQL
SELECT it.id, it.Code, it.Description, it.Rate, it.Bottles, it.Supply,
        it.Empty, it.Amount, it.Received, cn.Opening_Date, cn.Clients_Title, cn.Cust_Id
FROM Items AS it INNER JOIN Customer_New AS cn on it.Cust_Id=cn.Cust_Id
 
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