'Incorrect values in array
While I execute code I receive an error for variable template in "if" that says:
Value cannot be zero/null. Parameter: source
int id =Convert.ToInt32(GetCurrentColumnValue("ID"));
var query = string.Format("SELECT ttw_value1663 from mvv.tg_towary_mv where ttw_idtowaru = {0}", id);
var result = DbManager.Execute(query) ;
int[] template= result.GetValue<int[]>(0,0);
if (template.Contains(2181))
{
Detail.Visible=false;
}
I checked query using PgAdmin and I have 2 values inside. Data example: array int[2181,2182]
Solution 1:[1]
Okay, SQL is smart. I just converted array in query to text and it works just fine.
Complete code:
public void XtraReport_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
// List<int> templates =new List<int>();
int id = Convert.ToInt32(GetCurrentColumnValue("ID"));
var query = string.Format("SELECT ttw_value1663::text from mvv.tg_towary_mv where ttw_idtowaru = {0}", id);
var result = DbManager.Execute(query);
string template = result.GetValue<string>(0,0);
label5.Text = template;
// for (int i = 0; i < template.Length; i++)
//{
// templates.Add(template[i]);
//}
if (template.Contains("2181"))
{
Detail.Visible = false;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | marc_s |
