且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用sql中的过程向Giridview添加新行

更新时间:2023-11-30 22:37:10

该行为的原因在于此行:

其中 dbo.Service.ID=@ServiceID dbo.InsuraceCost.InsuraceID = @ InsuranceID



如果您想显示所有记录,请删除 where 语句或其中一个条件。


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

The reason of that behaviour is in this line:
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.