Can't figure out why this won't work. I get the same "Specified Cast is Invalid" error message. New to C#, be kind. It fails at the if(!((int)WrkRow["ManualWeight"] == 1 | etc. line. I tried a few variations of code, not all pasted here. ManualWeight is a number field in the table.
if (dt.Rows.Count > 0)
{
DataRow WrkRow = dt.Rows[0]; // ds.Tables(0).Rows(0)
if (mod1.IsTareout == true)
trim = (string)WrkRow["Trucker"];
sBarcode = $"{trim.Trim()}{(string)WrkRow["TruckNo"]} ";
XRSwatLaserCert rSwatLaserCert = new XRSwatLaserCert();
rSwatLaserCert.DataSource = dt;
DevExpress.XtraReports.UI.ReportPrintTool rpt = new DevExpress.XtraReports.UI.ReportPrintTool(rSwatLaserCert);
{
XRBarCode XrBCTareOut = new XRBarCode();
rSwatLaserCert.XrBCTareOut = new XRBarCode
{
Text = sBarcode
};
if (!((int)WrkRow["ManualWeight"] == 1 | (int)WrkRow["ManualWeight"] == 3))
{
rSwatLaserCert.XrLabelManualGross1.Visible = false;
rSwatLaserCert.XrLabelManualGross2.Visible = false;
rSwatLaserCert.XrLabelManualGross3.Visible = false;
}
2nd Try:
if (dt.Rows.Count > 0)
{
DataRow WrkRow = dt.Rows[0]; // ds.Tables(0).Rows(0)
if (mod1.IsTareout == true)
trim = (string)WrkRow["Trucker"];
sBarcode = $"{trim.Trim()}{(string)WrkRow["TruckNo"]} ";
XRSwatLaserCert rSwatLaserCert = new XRSwatLaserCert();
rSwatLaserCert.DataSource = dt;
DevExpress.XtraReports.UI.ReportPrintTool rpt = new DevExpress.XtraReports.UI.ReportPrintTool(rSwatLaserCert);
{
XRBarCode XrBCTareOut = new XRBarCode();
rSwatLaserCert.XrBCTareOut = new XRBarCode
{
Text = sBarcode
};
if (WrkRow.Field<int>("ManualWeight") != 1 | (int)WrkRow.Field<int>("ManualWeight") != 3)
{
rSwatLaserCert.XrLabelManualGross1.Visible = false;
rSwatLaserCert.XrLabelManualGross2.Visible = false;
rSwatLaserCert.XrLabelManualGross3.Visible = false;
}
3rd try:
if (dt.Rows.Count > 0)
{
DataRow WrkRow = dt.Rows[0]; // ds.Tables(0).Rows(0)
if (mod1.IsTareout == true)
trim = (string)WrkRow["Trucker"];
sBarcode = $"{trim.Trim()}{(string)WrkRow["TruckNo"]} ";
XRSwatLaserCert rSwatLaserCert = new XRSwatLaserCert();
rSwatLaserCert.DataSource = dt;
ReportPrintTool rpt = new ReportPrintTool(rSwatLaserCert);
{
XRBarCode XrBCTareOut = new XRBarCode();
rSwatLaserCert.XrBCTareOut = new XRBarCode
{
Text = sBarcode
};
var manweight = WrkRow.Field<int>("ManualWeight");
if (manweight != 1 | manweight == 3)
{
rSwatLaserCert.XrLabelManualGross1.Visible = false;
rSwatLaserCert.XrLabelManualGross2.Visible = false;
rSwatLaserCert.XrLabelManualGross3.Visible = false;
}