DataRow[] rows = myDataSet.Tables[0].Select("name = '" + _string + "'");
If _string contains UNICODE characters, do I need to prefix it with N like in TSQL?
DataRow[] rows = myDataSet.Tables[0].Select("name = N'" + _string + "'");
Thanks!
DataRow[] rows = myDatatable.Select("name = '" + _string + "'");
_string includes Myanmar Unicode string and wrong result returns(i.e. it returned all strings that include Myanmar Characters).
What's wrong with me?
I also tried
myDatatable.DefaultView.RowFilter("name = '" + _string + "'");
the same wrong result return.
I tested it. Adding an N-Prefix will throw an exception.
You don't need to put the N-Prefix even if you are working with Unicode characters.
Related
I have this row filter text:
"[add1] = '" + startAddress+ "%" + middle+ "%" + end +"'"
which fails, but if I put the % at the beginning or end it's OK.
Is there any way to achieve the same result (i.e. "any" string in the middle of the names)?
Full statement is:
dv = new DataView(MyDataTable, "[add1] = '" + startAddress+ "%" + middle+ "%" + end + + "'", "", DataViewRowState.CurrentRows);
Here i want filteration like "%something%someone%" How can i achieve this? Even using linq is also ok with me
I have this row filter text: "[Name 1] = '" + forename + "%" + surname + "'" which fails, but if I put the % at the beginning or end it's OK. Is there any way to achieve the same result (i.e. "any" string in the middle of the names)?
Full statement is:
dv = new DataView(MyDataTable,
"[Name 1] = '" + forename + "%" + surname + "'",
"", DataViewRowState.CurrentRows);
Just a free thougth, try:
dv = new DataView(MyDataTable,
"[Name 1] = '" + forename + "%' AND [Name 1] = '%" + surname + "'",
"", DataViewRowState.CurrentRows);
EDIT: some documentation:
"A wildcard is allowed at the start and end of a pattern, or at the end of a pattern, or at the start of a pattern. [...] Wildcard characters are not allowed in the middle of a string. For example, 'te*xt' is not allowed."
My guess would be it's for performance reasons (?)
I am adding mutliple values to single string , all the values should be like in this format '','' but I am getting "'',''" instead.
How can I remove these double qoutes? Here's the code I'm using:
string one = "\'"+ names[0, 0] +"\'"+","+"\'" + names[1, 0]+"\'";
string[] splitted = one.Split('\'');
string ones = "'" + splitted[1] + "'" +","+ "'" + splitted[3] + "'";
You don't have to escape single quote like "\'" instead you can simply use "'", so you code should be:
string one = "'" + names[0, 0] + "'" + "," + "'" + names[1, 0] + "'";
string[] splitted = one.Split('\'');
string ones = "'" + splitted[1] + "'" + "," + "'" + splitted[3] + "'";
Not sure I fully understand, but there are two ways.
Output: ".","."
var s1 = #"""."","".""";
var s2 = "\".\",\".\"";
The best way to encapsualte escape sequences and special characters within a string is the use of webatim character.
e.g.
String escSeq = "C:\\MyDocuments\\Movie";
can also be stored as:
string escSeq = #"C:\MyDocumens\Movie";
The # character you must put before the string starts and outside the "" characters.
I just worked with your code..it works just fine..
Debugger will show: "'val1','val2'"
Actual Value : 'val1','val2'
From the debugger point you will see "'val1','val2'" but actually it happens for every string values. but actually when you prints the value in a page you will see the actual value as 'val1','val2'
EDIT:
For sending those values to javascript what you can do is just set those values in Hidden fields and then fetch those value from that using document.getElementById('hidden_field').
Okay, so in the past few weeks I've probably written about 40 select statements. So, I know how to do it. And I've just written another one, but this time I need to use ComboBox values to match against, and it keeps resulting in the names of the column (the right column, mind you), instead of what's inside the column.
string st = "SELECT '" + txtchange.Text + "'
FROM mysql_9269_dbase." + pages.Text + "";
MySql.Data.MySqlClient.MySqlCommand cd = new MySql.Data.MySqlClient.MySqlCommand(st, msc);
cd.CommandType = CommandType.Text;
MySql.Data.MySqlClient.MySqlDataReader msdr = cd.ExecuteReader();
while(msdr.Read())
{
txt.Text = msdr[0].ToString();
}
Now, why is it returning the column name instead of the content of that column?
Lose the single quotes.
Change
"SELECT '" + txtchange.Text + "' "
to
"SELECT " + txtchange.Text + " "
In sql you can do it like this.
string query = "Execute("+"'SELECT " + txtchange.Text + " FROM mysql_9269_dbase." + pages.Text + "')";
I've a datatable with a column containing GUIDs. I want to select a row matching a specific GUID. I wrote the following code,
DataRow[] dRows = dtListSettings.Select("ListGUID = " + Convert.ToString(ViewState["GUID"]));
The GUID i'm comparing is 500c2b6a-a3a7-457f-90ed-c96768d91520. But i'm getting the error - Syntax error: Missing operand after 'c2b6a' operator.
Any ideas?
Thank you
NLV
Need a single quote:
Something like:
string.Format("ListGUID = '{0}'", Convert.ToString(ViewState["GUID"]));
Try surrounding your select statement parameter in single quotes, like this:
DataRow[] dRows = dtListSettings.Select("ListGUID = '" + Convert.ToString(ViewState["GUID"]) + "'");
This does not work for IN. E.g.
DataRow[] dRows = dtListSettings.Select("ListGUID IN ('" + Convert.ToString(ViewState["GUID"]) + "')");
I resolve this with two bellow methods:
DataTable dt = new DataTable(); // your datatable with data
Guid gid = Guid.NewGuid(); // searching guid
DataRow[] dra = dt.Select("GuidColumn = '" + gid.ToString() + "'")
// OR
DataRow[] dra = dt.Select("GuidColumn = Convert('" + gid.ToString() + "', 'System.Guid')");
hope be useful ;)