2011-12-19 54 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"]