使用Select()的特定字符串的DataSet搜索列 [英] DataSet search colum for specific string using Select()

查看:93
本文介绍了使用Select()的特定字符串的DataSet搜索列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般的想法是将文本文件中的ASCII数据添加到DataSet中的现有数据中,第一个txt文件字符串与DataSet列相同,但不是以相同的顺序。



我尝试在一个列中搜索特定的字符串并向其添加数据。我收到错误消息无法解释令牌......



我尝试使用DataSet.Tables []搜索行。选择()



搜索字符串是column ='searchstring'

brtoc是DataSet中的列,ucitavanje_brtoc是来自ASCII文件的相同字符串。



string a =\brtoc++=++'+ ucitavanje_brtoc +'+\;

MessageBox.Show(a); //只是为了查看输出字符串是否正确



DataRow addbazaRow = gui1DataSet.Tables [baza]。选择(a).FirstOrDefault();



//将数据添加到现有行的代码



我做错了什么?





谢谢



注意:这是我在VS的第一个项目,我是一个菜鸟:)

抱歉我的英语不好

解决方案

尝试删除搜索字符串周围的转义引号。在构建搜索字符串时尝试使用此...

  string  a =   brtoc +   +   = +    +  ' + ucitavanje_brtoc +  '; 



此外,这是相同的事情,但简化连接...

<前lang =c#> 字符串 a = brtoc =' + ucitavanje_brtoc + < span class =code-string>';


General idea is to add ASCII data from text file to existing data in DataSet, first string of txt file is the same as DataSet column, but not in the same order.

I try to search one colum for specific string and add data to it. I get error message "cannot interpret token ""......"

I tryed to search rows using DataSet.Tables[].Select()

search string is "column = 'searchstring'"
brtoc is column in DataSet, ucitavanje_brtoc is the same string from ASCII file.

string a = "\"brtoc" + " " + "=" + " " + "'" + ucitavanje_brtoc + "'" + "\"";
MessageBox.Show(a); //just to see if output string is ok

DataRow addbazaRow = gui1DataSet.Tables["baza"].Select(a).FirstOrDefault();

// code to add data to existing row

What am i doing wrong?


Thank You

note: this is my first project in VS, and i'm a noob :)
sorry for my bad english

解决方案

Try removing the escaped quotes around your search string. Try using this when you build your search string...

string a = "brtoc" + " " + "=" + " " + "'" + ucitavanje_brtoc + "'";


Also, here's the same thing but with simplified concatenation...

string a = "brtoc = '" + ucitavanje_brtoc + "'";


这篇关于使用Select()的特定字符串的DataSet搜索列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆