I am working on a MS Bot Framework project where I am retrieving the value from a key-value pair from database in C#. Previously I had this:
var list = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(obj,_Obj.Questions)
};
Dictionary<int, string> d = new Dictionary<int, string>
{
{ 1, "Welcome, How are you?" },
{ 2, "Tell me something about yourself."},
{ 3, "How much experience do you have?"},
};
My goal was to bring the Values such as "Welcome, How are you?", "Tell me something about yourself", etc from database. In order to achieve that I did this:
Edit:
Questions.cs
public static string GetChats(int Id)
{
using (SqlCommand cmd = new SqlCommand("usp_FetchData", con))
{
var list = new List<KeyValuePair<int, string>>();
DataTable dt = new DataTable();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", Id);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
foreach (DataRow row in dt.Rows)
{
string queMsg = row["Description"]?.ToString();
list.Add(new KeyValuePair<int, string>(Id, queMsg));
}
}
// class property
public string WelcomeStmt = GetChats(1).ToString();
And the value from above function is getting in this method:
MyDialog.cs // this is the dialog for the Bot
private static async Task<DialogTurnResult> **NameStepAsync**(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text(questions.AskName) }, cancellationToken);
}
I am passing the Id value as 1 in GetChats(Id) method. So based on that, I should get the corresponding Value.
In the NameStepAsync method, I am receiving an unusual parent class I guess instead of actual string that I am expecting.:
System.Collections.Generic.List1[System.Collections.Generic.KeyValuePair2[System.Int32,System.String]].
Does anybody know why this is happening?
Thanks.