Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 472.2k

How to map your parameters correctly in wpf using c#?

Jul 23 2024 12:53 PM

Hi Team

I am experience this problem, but i am using the correct parameters. I want to get latest batchNumber sequentially so that when the windows application is opened. There should be that number and should increment every time user open the screen.

 

  Name Value Type
? $exception {"The column DateCaptured was not found on the IDataRecord being evaluated. This might indicate that the accessor was created with the wrong mappings."} System.InvalidOperationException

 

 

USE [Adroit_Batch_Suite]
GO

/****** Object:  StoredProcedure [dbo].[spGetPremixSheet]    Script Date: 2024/07/23 13:22:58 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[spGetPremixSheet]
    @procOption NVARCHAR(50),
    @Batch INT = NULL,
    @DateCaptured DATE = NULL,
    @Code NVARCHAR(50) = NULL,
    @Phase NVARCHAR(100) = NULL,
    @Quantity DECIMAL(18, 2) = NULL,
    @Comments NVARCHAR(MAX) = NULL,
    @PrintedBarCodes INT,
    @UnusedBarcodes INT,
	@UsedBarCodes INT,
    @PrintedVar INT,
    @UserVar INT
    
AS
BEGIN
    SET NOCOUNT ON;

    IF @procOption = 'All'
    BEGIN
        SELECT Batch, DateCaptured, Code, Phase, Quantity, Comments, PrintedBarCodes, UnusedBarcodes, UsedBarCodes,PrintedVar, UserVar
        FROM [dbo].[Adr_Batch_PremixControl]
    END
    ELSE IF @procOption = 'PK'
    BEGIN
        SELECT Batch, DateCaptured, Code, Phase, Quantity, Comments, PrintedBarCodes, UnusedBarcodes, UsedBarCodes,PrintedVar, UserVar 
        FROM [dbo].[Adr_Batch_PremixControl] 
        WHERE Batch = @Batch;
    END
    ELSE IF @procOption = 'Date'
    BEGIN
        SELECT Batch, DateCaptured, Code, Phase, Quantity, Comments, PrintedBarCodes, UnusedBarcodes, UsedBarCodes,PrintedVar, UserVar
        FROM [dbo].[Adr_Batch_PremixControl]
        WHERE DateCaptured = @DateCaptured;
    END
    ELSE IF @procOption = 'LatestBatchNumber'
    BEGIN
        SELECT TOP 1 Batch
        FROM [dbo].[Adr_Batch_PremixControl]
        ORDER BY Batch DESC;
    END
END
GO



//xaml.cs   

public frmPremixPostData()
        {
            InitializeComponent();
            presenter = new ManagePremixBatchPresenter(this);
            this.DataContext = this;
            this.Loaded += FrmPremixPostData_Loaded;
            
            
        }

        //incrementing a batch number sequentially.
        private void FrmPremixPostData_Loaded(object sender, RoutedEventArgs e)
        {
            int batchNumber = presenter.GetNextBatchNumber(batchNo);
            presenter.GetDateForBatch(batchNumber);
            BatchTextBox.Text = batchNumber.ToString();
        }



//presenter.cs
public int GetNextBatchNumber(int batchNo)
        {
            Managers.PremixControlManager.SetAdriotConnection();

            try
            {
                // Get the latest batch number from the database
                var latestBatchControl = Managers.PremixControlManager.GetLatestBatchNumber(batchNo);
                // Increment the batch number to get the next one
                var nextBatchNumber = latestBatchControl.Batch + 1;

                return nextBatchNumber;
            }
            catch (Exception ex)
            {
                // Log the exception or handle it appropriately
                Console.WriteLine($"Error in GetNextBatchNumber: {ex.Message}");
                throw; // Rethrow the exception to propagate it further if needed
            }
            finally
            {
                Managers.PremixControlManager.SetDefaultConnection();
            }
        }



//manager.cs
 public static PremixControl GetLatestBatchNumber(int batchNo)
        {
            var result = DataAccessProvider.GetEntity<PremixControl>(
                PremixControl.PROC_NAME_GET,
                new object[] { "LatestBatchNumber", DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, 0, 0, 0, 0, 0 });

            if (result == null)
            {
                result = new PremixControl();
            }

            return result;
        }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Feedmill_Weighbridge.Entities
{
    class PremixControl
    {
        public const string PROC_NAME_GET = "[dbo].[spGetPremixSheet]";
        public const string PROC_PNAME_GET = "[dob].[spGetPremixBatchTest]";


        public PremixControl()
        {

        }

        public int Batch { get; set; }
        public DateTime? DateCaptured{ get; set; }
        public string Code { get; set; }
        public string Phase { get; set; }
        public decimal ? Quantity { get; set; }
        public string Comments { get; set; }
        public int PrintedBarCodes { get; set; }
        public int UnusedBarcodes { get; set; }
        public int UsedBarCodes { get; set; }
        public int PrintedVar { get; set; }
        public int UserVar { get; set; }
        
    }
}

 


Answers (1)