Click here to Skip to main content
15,904,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use the "Procedure_SELECT" to add a row to the grid view, but each time a new row is displayed only.
System.Data.DataTable ServiceInsuranceList;


<pre lang="cs"><pre lang="cs">private void BtnSave_Click(object sender, EventArgs e)
     {
         int ServiceID = Convert.ToInt32(CmbService.SelectedValue);
         int InsuranceId = Convert.ToInt32(CmbInsurance.SelectedValue);

         if (ServiceInsuranceList == null)
         {
             ServiceInsuranceList = new System.Data.DataTable();
             ServiceInsuranceList = HLP.Business.Object.Services.ServiseInsuranceList(InsuranceId, ServiceID);
            
                 GrdServiceInsurance.DataSource = ServiceInsuranceList;
         }
         else
         {
             ServiceInsuranceList.NewRow();
             ServiceInsuranceList.AcceptChanges();
             ServiceInsuranceList = HLP.Business.Object.Services.ServiseInsuranceList(InsuranceId, ServiceID);
             if (ServiceInsuranceList != null)
                 GrdServiceInsurance.DataSource = ServiceInsuranceList;
         }




     }&lt;/pre&gt;</pre>


public static DataTable ServiseInsuranceList(int InsuranceID, int ServiceID)
       {
           DataTable PoseDataTable = new DataTable();
           SqlCommand Command = HLP.Data.DataProvider.GenerateCommand("Clinic_ServiceInsuranceList", CommandType.StoredProcedure);
           Command.Parameters.AddWithValue("@InsuranceID", InsuranceID);
           Command.Parameters.AddWithValue("@ServiceID", ServiceID);


           try
           {
               Command.Connection.Open();
               Command.ExecuteNonQuery();
               PoseDataTable = HLP.Data.DataProvider.GenerateDataTable(Command, CommandType.StoredProcedure);
           }
           catch (Exception ex)
           {

           }
           finally
           {
               HLP.Data.DataProvider.DisposeCommand(Command);
           }
           return PoseDataTable;
       }



MY PROCEDURE:

ALTER PROC [dbo].[Clinic_ServiceInsuranceList]
@ServiceID INT ,
@InsuranceID INT 
as
BEGIN
SELECT     Service.Title, Service.Code, ActCostService.Cost, InsuranceServiceCost.Cost AS Expr1, InsuraceCost.InsuraceID
FROM         InsuraceCost INNER JOIN
                      InsuranceServiceCost ON InsuraceCost.ID = InsuranceServiceCost.InsuraceCostID LEFT OUTER JOIN
                      Service ON InsuranceServiceCost.ServiceID = Service.ID FULL OUTER JOIN
                      ActCostService ON Service.ID = ActCostService.ServiceID
                      where 
                      dbo.Service.ID=@ServiceID and
                      dbo.InsuraceCost.InsuraceID=@InsuranceID
                      
end
Posted
Updated 30-Apr-14 19:55pm
v2
Comments
ZurdoDev 1-May-14 9:34am    
What is your question?
je30ca 1-May-14 12:58pm    
I want the PROCEDURE I add new row in the grid view, but each time the previous data is deleted and new data is displayed!How can I add a new row in giridview?!

1 solution

The reason of that behaviour is in this line:
SQL
where dbo.Service.ID=@ServiceID and dbo.InsuraceCost.InsuraceID=@InsuranceID

If you would like to display all records, remove where statement or one of the condition.
 
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