Reputation: 47
I was getting an error about trying to push null into the field, which was a Foreign key in the table I was using. So I changed it, but I am not sure if I grabbed the right object, so I want to print what I just pushed the database table. I am aware that I can query the table, but given that I only see the id, and it is almost midnight, I feel better if I can just print it and make sure it is the value I just created in the form. Here is the code...
foreach (TeamModel tm in model.EnteredTeams)
{
var p = new DynamicParameters();
p.Add("@TournamentId", model.Id);
//p.Add("@PrizeId", tm.Id);
//p.Add("@PrizeId", model.Prizes);
p.Add("@PrizeId", model.Prizes.First().Id);
p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
connection.Execute("spTournamentPrizes_Insert", p, commandType: CommandType.StoredProcedure);
MessageBox.Show("This is the prize you just pushed to the Database." , model.Prizes.First());
}
As you can see I am trying to use MessageBox, but it is only for strings apparently according to the documentation I read. How can I print what is the Prize object?
Upvotes: 0
Views: 495
Reputation: 457
Here is what i would do:
Write a method to convert Prize object to string inside Prize class like:
public string GetPrizeDetailsAsString()
{
return "ID:"+Id.ToString()+..... // u can add all the params from prize which u wanna view;
}
then calling model.Prize.First().GetPrizeDetailAsString() will give you the complete details.
eg:
MessageBox.Show("This is the prize you just pushed to the Database." , model.Prizes.First().GetPrizeDetailAsString());
Upvotes: 3
Reputation: 1
You can write method to return the values from the Prize object.
public string ConvertPrizeToString(Prize prize)
{
return string.Format("Id:{0}, Other Details:{1}", prize.Id, prize.OtherDetails);
}
Then you can call the function in MessageBox
MessageBox.Show("This is the prize you just pushed to the Database.", ConvertPrizeToString(model.Prizes.First()));
Upvotes: 0