データベーステーブルから単語をロードするシステムを構築しましたが、それらの単語を「Choices」タイプ (Grammar Building に必要なタイプ) のリストに追加する必要があります。
これは、データベースから単語を取得するように要求するための私のコードです。
List<string> newWords = new List<string>();
newWords = LexicalOperations.WordLibrary().ToList();
Choices dbList = new Choices(); //Adding them to a Choice List
if (newWords.Count != 0)
{
foreach (string word in newWords)
{
dbList.Add(word.ToString());
}
}
else dbList.Add("Default");
これは、テーブルからデータを取得する私のコードです。
public class LexicalOperations
{
public static List<string> WordLibrary()
{
List<string> WordLibrary = new List<string>();
string conString = "Data Source=.;Initial Catalog=QABase;Integrated Security=True";
using (SqlConnection connection = new SqlConnection(conString))
{
connection.Open();
string sqlIns = "select WordList from NewWords";
SqlCommand cmd = new SqlCommand(sqlIns, connection);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
WordLibrary.Add(dr[0].ToString());
}
}
return WordLibrary;
}
}
ただし、これは例外をスローします: System.FormatExceptionもメッセージを示します:
FormatException が処理されませんでした
二重引用符で囲まれた文字列は無効です。
Speech Grammar Builder で選択肢リストを作成すると、次のエラーがスローされます。
GrammarBuilder graBui = new GrammarBuilder(dbList);
Grammar Gra = new Grammar(graBui);
私は何を間違っていますか?データベースから単語を適切に取得して Choice リストに追加するには、どうすればよいですか?