0

私のコードの何が問題になっていますか?

  string birthdate = ((DataRowView)comboBox1.SelectedItem).Row["birthdate"].ToString(); //pulled the data into the database ()

string[] split = birthdate.Split('/'); //split the Date

それらをテキストボックスに入れたいので、これを行うことを考えました。

textbox1.Text = split[0]; //correct, gets the 1st word the (Day)
    textbox2.Text = split[1]; //incorrect, outofrange exception (Month)
    textbox3.Text = split[2]; //incorrect, outforange exception (Year)

注:形式は、日/月(単語)/年==> 1 /January/2012です。

誰かが私がその値を取得してテキストボックスに1つずつ入れるのを手伝ってもらえますか?

4

1 に答える 1

2

この問題は、日付を varchar 型の列に格納することから始まりました。カルチャが正しく設定されていない 1 台のマシンだけでデータベース テーブルが破損するため、それを読み取ろうとするすべてのマシンが爆破されます。実際の問題を解決し、テーブルを修正します。

とにかく、コードを改善して、dbase 管理者が損傷を修復するための戦闘チャンスを得られるようにする必要があります。十分な情報を提供する例外をスローします。何かのようなもの:

string[] split = birthdate.Split('/');
if (split.Length != 3) {
    throw new Exception("Invalid date string for table entry " + row["primarykey"].ToString());
}
于 2012-01-21T16:32:57.733 に答える