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.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; }
}
}
Naimish MakwanaPosted Jul 24, 2024, 10:55 AM
The error message you’re seeing indicates that the
DateCapturedcolumn was not found on theIDataRecordbeing evaluated. This could be due to a few reasons:The column doesn’t exist in the table: Make sure the
DateCapturedcolumn exists in the[dbo].[Adr_Batch_PremixControl]table.The column is not being returned by the stored procedure: In your stored procedure
[dbo].[spGetPremixSheet], make sure theDateCapturedcolumn is included in theSELECTstatement for all theIFconditions.The column is not being mapped correctly in the data access layer: In your
DataAccessProvider.GetEntitymethod, ensure that theDateCapturedproperty of thePremixControlclass is being correctly mapped to theDateCapturedcolumn in the database.The column is not being used correctly in the application code: In your
FrmPremixPostData_Loadedmethod, make sure you’re not trying to access theDateCapturedproperty if it could benull.Please check these points and see if it resolves your issue. If the problem persists, you might want to debug your application and step through the code to see where the
DateCapturedcolumn is being accessed and why it might not be available at that point.Thanks