This topic is locked
[SOLVED]

 FK values in email message

2/1/2017 7:25:37 PM
ASPRunner.NET General questions
jadach authorDevClub member

I am trying to email data after the record is updated. I am using a FK value so right now the raw value is "1". I would like to send the displayed value "Approved" from the lookup table.
I tried looking here for help, but cannot figure out how to incorporate into my code.

https://xlinesoft.com/asprunnernet/docs/data_formatting.htm
Here is my code snippet:
string msg = "Status: "+values["Status"].ToString()+"";
Thank you for any help with this.

M
Mack88DevClub member 2/1/2017

Hi Jerry,
Totally new ground for me, but have you tried the ViewControl::Format(data, "<FieldName>", "<TableName>"); function?
Cheers,
Chris

jadach authorDevClub member 2/1/2017

Yes, but it didn't like that. Perhaps my syntax was wrong. I check in visual studio and it red lined view control as not recognizing it.

M
Mack88DevClub member 2/1/2017



Yes, but it didn't like that. Perhaps my syntax was wrong. I check in visual studio and it red lined view control as not recognizing it.


I tried a test event and got a CS0687 error The namespace alias qualifier '::' always resolves to a type or namespace so is illegal here. Consider using '.' instead.. Replacing the '::' with the '.' throws an error in ViewControl.cs.
Worth a support ticket?

jadach authorDevClub member 2/2/2017

Perhaps. Maybe I will leave this out for another day. if no help arrives, I will put a support ticket in.

jadach authorDevClub member 2/2/2017

I am confident there is a better way, but this worked for me.
After Record Update, I added a data reader to create a session variable I can use in the email message.

using (System.Data.SqlClient.SqlConnection sql_I = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["YourConnectionStringNameFromWebConfig"].ConnectionString))

{

sql_I.Open();

string qry_Reader = "SELECT * FROM [dbo].[LUStatus] WHERE [StatusID] = '" + values["Status"].ToString() + "'";

using (System.Data.SqlClient.SqlCommand cmd_Reader = new System.Data.SqlClient.SqlCommand(qry_Reader, sql_I))

{

using (System.Data.SqlClient.SqlDataReader rdr_Reader = cmd_Reader.ExecuteReader())

{

if (rdr_Reader.HasRows)

{

while (rdr_Reader.Read())

{

XSession.Session["StatusID"] = rdr_Reader["Status"].ToString();

}

}

else

{

XSession.Session["StatusID"] = "";

}

rdr_Reader.Close();

}

}

}
string email = "ToEmailAddress";

string from = "FromEmailAddress";

string msg = "Status: "+values["Status"].ToString()+"<br />"+XSession.Session["StatusID"].ToString()+"";

string subject = "Status Update";

XVar attachments = XVar.Array();

XVar result;

result = MVCFunctions.runner_mail(new XVar("to", email, "subject", subject, "htmlbody", msg, "from", from, "attachments", attachments));

if(!result["mailed"])

{

MVCFunctions.EchoToOutput(result["message"]);

}
admin 2/3/2017

Just wanted to say that there is an error in the manual and we'll fix it shortly.
The following syntax works:

ViewControl.Format(data, "<FieldName>", "<TableName>");
jadach authorDevClub member 2/5/2017

Thanks, but I still can't figure out the syntax to make this work.
string msg = "Status: "+values["Status"].ToString()+"";
Am I substituting values["Status"] with ViewControl.Format(data, "Status", "LUStatus");
Or am I not looking at this correctly?

admin 2/6/2017

Yes, you can try ViewControl.Format(values, "Status", "LUStatus") or ViewControl.Format(values, "Status", "LUStatus").ToString()

jadach authorDevClub member 2/7/2017



Yes, you can try ViewControl.Format(values, "Status", "LUStatus") or ViewControl.Format(values, "Status", "LUStatus").ToString()


Thanks Sergey. However when I do this, I still get the int value (StatusID), not the text.
string msg = "Status:<br /> "+ViewControl.Format(values, "Status", "LUStatus").ToString()+"";
My LUStatus table is as so:
StatusID Status

1 Shipped

2 Hold

3 Pending

jadach authorDevClub member 2/7/2017



Thanks Sergey. However when I do this, I still get the int value (StatusID), not the text.
string msg = "Status:<br /> "+ViewControl.Format(values, "Status", "LUStatus").ToString()+"";
My LUStatus table is as so:
StatusID Status

1 Shipped

2 Hold

3 Pending


My bad. I was using the lookup table instead of the table containing the data. Thank Sergey, works like a charm.
Mike, if you are following, here is our answer. Much better than the way I told you.
The right way is: string msg = "Status:<br /> "+ViewControl.Format(values, "Status", "dbo.Apply").ToString()+"";