2011-12-19 8 views
0

テキストボックスからの値の後にデータテーブルの列を検索したいとします。今データセットのデータテーブルから値を読み取る

DataColumn bookName = new DataColumn("BookName", typeof(string)); 
DataColumn bookId = new DataColumn("BookId", typeof(int)); 
DataColumn isbn = new DataColumn("ISBN", typeof(string)); //should be an EAN-13 
Barcodeenter code here 

DataColumn book_authorId = new DataColumn("Book_AuthorId", typeof(int)); 
DataColumn bookprice = new DataColumn("Price", typeof(decimal)); 
DataColumn authorName = new DataColumn("AuthorName", typeof(string)); 
DataColumn authorId = new DataColumn("AuthorId", typeof(int)); 
DataColumn geschlecht = new DataColumn("Geschlecht", typeof(string)); 

、私は全体のテーブルから値を取得することなく、どのように私は、ISBNを検索することができます:私はこれが私の表「ブック」である

ISBN-番号の後に検索したいですか? リストボックスには出力があります。 ISBN番号にテキストボックスのテキストが含まれている本から、すべての値を取得したいと考えています。

私はISBN後に検索するために今持っている私のコードは以下の通りです:

string isbn = _tbIsbnSuche.Text; 
      string result = String.Empty; 
      string file = _tempPath + @"\book_authorData.xml"; 
      XmlTextReader r = new XmlTextReader(file); 
      if (isbn != String.Empty) 
      { 
       _lbInformation.Text = String.Empty; 
       _lBdatenOutput.BackColor = Color.LightGoldenrodYellow; 
       _lBdatenOutput.Items.Clear(); 
       _lBdatenOutput.Items.Insert(0, "Please Wait!"); 
       _lBdatenOutput.Items.Insert(1, "Gefundene ISBN-Nummern:"); 
       while (r.Read()) 
       { 
        if (r.Value.Trim().IndexOf(isbn) != -1 && r.Value.Trim().Contains("-") && r.Value.Length >= 13) 
        { 
         _lBdatenOutput.Items.Add(r.Value.Trim()); 
        } 
       } 
       tim.Enabled = true; 
      } 
      else 
      { 
       _lbInformation.ForeColor = Color.Red; 
       _lbInformation.Text = _suchfehler; 
      } 
      //Wenn keine Datensätze gefunden wurden 
      if (_lBdatenOutput.Items.Count == 2) 
      { 
       tim.Enabled = true; 
       _lBdatenOutput.BackColor = Color.OldLace; 
       _lBdatenOutput.Items.Add(String.Concat("Es wurden keine Bücher welche in der ISBN-Nummer die Zeichenfolge ", "\"", isbn, "\"", " enthalten gefunden")); 

      } 

しかし、これは、データセットのすべてを検索し、私は他のフィールドwithchに値を持っている場合、検索文字列と同じです検索結果にも表示されます。

答えて

0

私は解決策を見つけました。この解決策はもっと複雑なものかもしれませんが、私は別の解決策を見つけることができませんでした。私はこの

を持つ人を助けることができると思います

string _seperator1 = "-------------------------------------------------------------------------------------------------------------------------------- \n"; 
string isbn = _tbIsbnSuche.Text; 
DataView custView = new DataView(_dset.Tables["Book"], "", "ISBN", DataViewRowState.CurrentRows); 
{ 
    _lBdatenOutput.Items.Clear(); //Delete existing Objects from the Output 
    foreach (DataRowView myDRV in custView) 
    { 
     DataRow dr = myDRV.Row; 
     if((dr["ISBN"].ToString().IndexOf(isbn) >= 0)) 
     { 
      foreach (DataColumn cl in custView.Table.Columns) 
      { 
       _lBdatenOutput.Items.Add("Spalten-Name: " + " \t " + cl.ColumnName + " \t" + dr[cl]); 
      } 
      _lBdatenOutput.Items.Add(_seperator1); //Insert a seperator 
     } 
    } 
} 

:いくつかの時間後、私は次のコードを持っています

0

DataRowの列には、名前などを使用してアクセスできます。 row["ISBN"]

関連する問題