私はC#を使用してWindowsプロジェクトを開発しています。テキストファイルレコードをsqlserver 2005 dbにインポートする必要があります。 私の質問は 学生Idnoを使ってテキストファイルからレコードを読みたい。キー値に基づいてテキストファイルに入力されたレコードを取得する方法
私は、学生番号:1001の値を見つけている文字列を使って、テキストファイルから正確な値を読み取るアイディアを持っています。 私は特定の生徒の番号に基づいてすべての生徒の記録を読みたいですか? not for 1001
私は学生番号に基づいて特定のレコードを読み取るために、スタンダードコードを として選択します。 plzはこの
|-----------------------------------------------| | student no:1001 | | address:ongole,A.P, | | hyderabad,india. | | ----------------------------------------------| | stdid stdname class | | 1 raheem mca | | 2 sudheer mca | | ----------------------------------------------| | student no:1001 | | address:ongole,A.P, | | hyderabad,india. | -|-------------------------------------------- | | stdid stdname class | | 1 raheem mca | | 2 sudheer mca | | ----------------------------------------------| | student no:1002 | | address:ongole,A.P, | | hyderabad,india. | ------------------------------------------------|- | student no:1003 | | address:ongole,A.P, | | hyderabad,india. | -|---------------------------------------------- |
よう
私のテキストファイルは、私のコードは、私はあなたの最善の策は、ラインを読むためのStreamReaderを使用することだと思う
private void BtnImpstrm_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
string f = openFileDialog1.FileName;
StreamReader sr = new StreamReader(f);
string s = sr.ReadToEnd();
MessageBox.Show(s);
sr.Close();
str =s.Split('\n');
for (int i = 0; i < str.Length; i++)
{
if (str[i].ToString().Trim().ToUpper().Contains("Student NO : 1001"))
{
string[] words = str[i].Split(' ');
string output = words[word no].ToString().Trim();
string rec1 =str[line no].ToString().Trim();
string rec2 = str[line no].ToString().Trim();
MessageBox.Show(output);
MessageBox.Show(rec1);
MessageBox.Show(rec2);
}
}
}
なぜあなたはいつもあなたのループで 'str [6]'と 'str [7]'を使っていますか? –
質問は表示されません。 – Amy
あなたはテキストファイルの形式を生成していますか? –