This topic is locked
[SOLVED]

 problem using record number as filename

12/7/2017 10:24:25 AM
ASPRunner.NET General questions
A
admin author

Hi Experts,

I am new with C# and asprunner.net!
This code in beforeAdd event dos not Work:
string sql = "SELECT MAX(bilid) as c FROM bildata";

XVar rs = tDAL.CustomQuery(sql);

XVar data = CommonFunctions.db_fetch_array(rs);

var rnoo = data["c"] + 1; 'hope this gives the new records ID??

if (!values["foto1"])

{

}

else

{

var fileArray = MVCFunctions.my_json_decode(values["foto1"]);

for(int i = 0; i < fileArray.Count(); i++)

{

var fileName = fileArray[i]["name"];

var newFileName = String.Format("files/{0}{1}.jpg", Convert.ToString(rnoo).ToLower() + "foto1", i);

System.IO.File.Move(MVCFunctions.getabspath(fileName), MVCFunctions.getabspath(newFileName));

fileArray[i]["name"] = newFileName;

}

values["foto1"] = Convert.ToString(rnoo).ToLower()+ "foto10.jpg";

}

// Place event code here.

// Use "Add Action" button to add code snippets.
return true;
This Works:

string sql = "SELECT MAX(bilid) as c FROM bildata";

XVar rs = tDAL.CustomQuery(sql);

XVar data = CommonFunctions.db_fetch_array(rs);

var rnoo = 905;

if (!values["foto1"])

{

}

else

{

var fileArray = MVCFunctions.my_json_decode(values["foto1"]);

for(int i = 0; i < fileArray.Count(); i++)

{

var fileName = fileArray[i]["name"];

var newFileName = String.Format("files/{0}{1}.jpg", Convert.ToString(rnoo).ToLower() + "foto1", i);

System.IO.File.Move(MVCFunctions.getabspath(fileName), MVCFunctions.getabspath(newFileName));

fileArray[i]["name"] = newFileName;

}

values["foto1"] = Convert.ToString(rnoo).ToLower()+ "foto10.jpg";

}

// Place event code here.

// Use "Add Action" button to add code snippets.
return true;
What am i doing wrong?? Thanks in advance

admin 12/7/2017

You need to run your app in Visual Studio in debug more and step through the code in this event to see what value 'rnoo' variable gets. You might need to convert data["c"] to integer before using it in calculations.

A
admin author 12/8/2017



You need to run your app in Visual Studio in debug more and step through the code in this event to see what value 'rnoo' variable gets. You might need to convert data["c"] to integer before using it in calculations.


Thank you for suggestion :-)

If i code following:
string sql = "SELECT MAX(bilid) as c FROM bildata";

XVar rs = tDAL.CustomQuery(sql);

XVar data = CommonFunctions.db_fetch_array(rs);

var rnoo = Convert.ToInt32(data["c"]) + 1;
I get following error compiling (sorry about the Danish part)
\\ ERP_LeaseBil_nu.csproj

Microsoft (R) Build Engine, version 4.7.2053.0

[Microsoft .NET Framework, version 4.0.30319.42000]

Copyright (C) Microsoft Corporation 2007. Alle rettigheder forbeholdes.
\\ ERP_LeaseBil_nuEventsCS.csproj

Microsoft (R) Build Engine, version 4.7.2053.0

[Microsoft .NET Framework, version 4.0.30319.42000]

Copyright (C) Microsoft Corporation 2007. Alle rettigheder forbeholdes.
include\bildata_TableEvents.cs(27,12): error CS0121: Kaldet er flertydigt for f›lgende metoder eller egenskaber: 'System.Convert.ToInt32(long)' og 'System.Convert.ToInt32(string)' [C:\Users\Auto\Documents\ASPRunnerNETProjects\ERP-LeaseBil.nu\output\ERP_LeaseBil_nuEventsCS.csproj]
What i need is the recordnumber of the record being added

Is there another way to get number of records in the current table?
Thank you in advance

A
admin author 12/9/2017



Thank you for suggestion :-)

If i code following:
string sql = "SELECT MAX(bilid) as c FROM bildata";

XVar rs = tDAL.CustomQuery(sql);

XVar data = CommonFunctions.db_fetch_array(rs);

var rnoo = Convert.ToInt32(data["c"]) + 1;
I get following error compiling (sorry about the Danish part)
\\ ERP_LeaseBil_nu.csproj

Microsoft (R) Build Engine, version 4.7.2053.0

[Microsoft .NET Framework, version 4.0.30319.42000]

Copyright (C) Microsoft Corporation 2007. Alle rettigheder forbeholdes.
\\ ERP_LeaseBil_nuEventsCS.csproj

Microsoft (R) Build Engine, version 4.7.2053.0

[Microsoft .NET Framework, version 4.0.30319.42000]

Copyright (C) Microsoft Corporation 2007. Alle rettigheder forbeholdes.
include\bildata_TableEvents.cs(27,12): error CS0121: Kaldet er flertydigt for f›lgende metoder eller egenskaber: 'System.Convert.ToInt32(long)' og 'System.Convert.ToInt32(string)' [C:\Users\Auto\Documents\ASPRunnerNETProjects\ERP-LeaseBil.nu\output\ERP_LeaseBil_nuEventsCS.csproj]
What i need is the recordnumber of the record being added

Is there another way to get number of records in the current table?
Thank you in advance


SOLVED :-)
string sql = "SELECT MAX(bilid) as c FROM bildata";

XVar rs = tDAL.CustomQuery(sql);

XVar data = CommonFunctions.db_fetch_array(rs);

int rnoo = data["c"] + 1; -----------------------------> now rnoo holds the recordnumber of the new record being added