Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
I wrote a function which returns DataTable. And called that function in button Click event so when the event is raised the function returns the data table and I am able to bind the data table to data grid. And the problem is when the button event is raised for the second time the data which is bound in the first event is not seen in datagrid when button event raised second time so need to display the old and new information in the data grid and all this is COMPACT FRAMEWORK->WINCE APPLICATION

THIS IS FUNCTION DEFINED

C#
public DataTable getdetails(ComboBox descp, ComboBox veitype)
        {
            InitializeDB();
            SqlCeCommand scmd = new SqlCeCommand();
            DataTable dt = new DataTable();
            SqlCeDataReader sdr;            
            try
            {
                scmd = con.CreateCommand();

                scmd.CommandText = "SELECT CHALLAN_CODE,CHALLAN_DESC,AMOUNT" + " FROM MB_MST_CHALLAN WHERE CHALLAN_DESC='" + descp.Text + "'AND (VEHICLE_TYPE='" + veitype.Text + "' OR VEHICLE_TYPE='A') AND STATUS='A'";
                SqlCeDataAdapter da = new SqlCeDataAdapter(scmd);
                da.Fill(dt);               
            }      
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                scmd.Dispose();
                CloseDbConnection();
            }
            return dt;
        }
Posted
Updated 30-Jun-10 23:23pm
v2

you need to merge the old datatable to new datatable
 
Share this answer
 
Can we Merge 2 data tables
if possible Can u guide me thru some code
 
Share this answer
 
<pre lang="vb">Dim dt1 As New DataTable
       dt1.Columns.Add("name")

       dt1.Rows.Add("NAME1")

       Dim dt2 As New DataTable
       dt2.Columns.Add("name")

       dt2.Rows.Add("NAME2")

       dt2.Merge(dt1)



but make sure that both table having same column names
 
Share this answer
 
DataTable dt = new DataTable();
DataTable dt1 = new DataTable();
dt.Columns.Add("Challan code");
dt.Columns.Add("Challan Desc");
dt.Columns.Add("amount");

dt1.Columns.Add("Challan code");
dt1.Columns.Add("Challan Desc");
dt1.Columns.Add("amount");

DataRow dr,dr1;
dr = dt.NewRow();
dt.Rows.Add(dr);
<big>dt= dbmgr.getdetails(chldesc, Vehtype);</big>
dataGrid1.DataSource = dt1;
 
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