2011-12-19 50 views
0

我想在文本框中的值後搜索數據表的列。我想ISBN號碼從數據集的數據表中讀取值

後搜索這是我的表「周易」:

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號包含文本框中文本的書中的所有值。

我的代碼我現在有書號後,搜索如下:

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

嘿,夥計們我找到了解決方案。這個解決方案可能比needet更復雜,但我找不到另一個解決方案。幾個小時後,我有下面的代碼:

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"]