|
Thanks. I'll look into that direction to solve the problem as well.
|
|
|
|
|
Hi All !
I use this Syntax for Filtering LastName field :
string strFilter = "LastName like '" + txtFamily.Text + "%'";
dvShowTable = new DataView(dataconn.dSet.Tables["PersonTable"], "", "", DataViewRowState.OriginalRows);
dvShowTable.RowFilter = strFilter;
dgShowTable.DataSource = dvShowTable;
if (dvShowTable.Count == 0)
{
MessageBox.Show("No find any Record !");
txtFamily.Text = "";
return;
}
It's works , but another filtering is about Account Field and I use this Syntax :
string strFilterAccount = "AccountNo like '" + Convert.ToDouble(txtAccount.Text)+"%'";
I have this Error:
Cannot perform 'Like' operation on System.Double and System.String
And If i use this syntax :
string strFilterAccount = "AccountNo="+ Convert.ToDouble(txtAccount.Text);
mmediately i put any Number , you get the message in the "If" conditional .
what is suitable instead of Like for number Field !
thanks
|
|
|
|
|
The LIKE operator is used only for string filtering, it cannot be used with numeric datatypes. You can try other operators like >= and <= etc.
|
|
|
|
|
Check out this MSDN page on the filter: http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx[^]
One thing it says is that the % sign should be between brackets [ ].
Like doesn't work for the double, so that's why you are getting that error. You need to use the compare operators, such as =. You say that is not working? Try putting a space between AccountNo and =, so: string strFilterAccount = "AccountNo = " + Convert.ToDouble(txtAccount.Text);
I wonder though, is Double really the proper type for an AccountNo? AccountNo sounds more like an integer to me.
|
|
|
|
|
MicroVirus wrote:
string strFilterAccount = "AccountNo = " + <br />
Convert.ToDouble(txtAccount.Text);
That shouldn't even compile, let alone work. Why convert to a Double whe you need a String for the filter...
|
|
|
|
|
Course it will, double has a ToString method which will be called at the +
Converting to a number and back is elementary validation, throwing an exception at that point rather than in the database query.
|
|
|
|
|
Way cool.
You mean I've been wasting keystrokes all this time actually putting in the .ToString() business?
|
|
|
|
|
I believe conversion from double to string is a widening conversion and thus can be done implicitly.
Anyway, your point about the there and back again conversion is right. I was more focused on solving the stated problem than watching what I copy-pasted.
The input should be validated beforehand, but this there-and-back-again method does avoid some SQL injection-like vulnerabilities.
|
|
|
|
|
Your code has SQL injection written all over it, though I'm not sure how protective the DataView is (i.e. whether it passes that filter through to any database level processor where it could do real damage). Even if it protects you in this instance, get into the habit of escaping anything you put in a query string (and that's what that filter string is).
I agree with MicroVirus that you probably want the account to be an int and use =. With double you can use int or you can use (AccountNo>=value-delta) AND (AccountNo<=value+delta) where delta is a comparison tolerance value which you should pick.
|
|
|
|
|
thanks for Your Replies ,
AccountNo is 13 digit , so i prefer to use to double ,
As i said , I want to Filter AccountNo , when i write "1" in the TextBox , and in the Result all of Records display that begin by "1" , when I write "2" after "1", display all Records begin "12" and etc.
Thanks !
|
|
|
|
|
Okay, to do that kind of string filtering you will need to store the ID as a string (or write a query with a conversion, but that's probably slow). This will prevent you from doing arithmetic on that column and, depending on your database, might be slow as a primary key, so you might want to have a separate column with a string version in it.
For large integers you should use long, not double.
|
|
|
|
|
As BobJanova said, this kind of code leaves you wide open to SQL injection attacks...
You might want to take a look at http://bobby-tables.com/[^] (Yes, it's funny, but it's also important)
|
|
|
|
|
The AccountNo field has a type of double in your database, which cannot be used with the 'like' operator. There are some solutions to this problem.
1. Change the type of AccountNo to text.
-or-
2. If you really want to use double for AccountNo, convert it to text in the query so that you can use the 'like' operator. The function to do the conversion may be different from one database engine to another. For example, in MySql, the function is 'cast', so something like this can be used:
string strFilterAccount = "cast(Accountno as char) like '" + Convert.ToDouble(txtAccount.Text) + "%'";
Considering that in many occasions an account number can really have letters and other non-digit characters in it, I think solution 1 may be better for you. (My water bill account number has letters and dashes embedded in it, for example)
SQL injection is a real issue here.
|
|
|
|
|
Thanks ,
apparently , There No solution for AccountNo , Unless I Change the DataType to Text .
But , if I define AccountNo to a Numeric DataType , Really , There is no solution for it.
By the Way wat is the equel of the "Cast" (in MySql ) for Sql . if we Use Cast , we get this Error !
The expression contains undefined function call cast().
Thanks a Lot !
|
|
|
|
|
If you are using Microsoft Access, the function to use is str(), like so:
string strFilterAccount = "str(Accountno) like '" + Convert.ToDouble(txtAccount.Text) + "%'";
SQL Server recognizes the 'cast' function. Please tell us what system you are using.
|
|
|
|
|
my DataBase is MsAccess , in spite of this , i get this Error !
The expression contains undefined function call str().
|
|
|
|
|
Sorry about the confusion. I was thinking that you were using a command object. Instead, you were using a DataTable. In this case, the function to use is 'Convert', like so:
string strFilterAccount = "CONVERT(AccountNo, 'System.String') like '" + Convert.ToDouble(txtAccount.Text) + "%'";
Hope this solves your problem.
|
|
|
|
|
how to transfer file from computer to terminal (windows-mobile) Through FTP
thanks in advance
|
|
|
|
|
|
I developed one website for my product.So now i would like to add some indian payment gateway API for the selling of my product through CC/Debit Card/Netbanking system.could anyone plz assist me for making that integration in to my site or please refer me some links on the same...
Thanks in Advance..
Srikanth P
|
|
|
|
|
You will probably need to contact the site that provides the gateway in the first instance.
|
|
|
|
|
|
hi
i transfer file from A to B Through WebService
after the was transfer i need to read his size.
i know how to do it, but when i try to read the file size i get:
The process cannot access the file XXX.XXX because it is being used by another process
what i can do ?
thanks in advance
|
|
|
|
|
Without knowing how your code works, we can only guess at the methods you used.
However, this kind of error normally comes up because the objects you created to access and copy the file have not been properly released, and are waiting for the Garbage Collector to come in and free them. The file will remain in use until that happens.
Look at your file transfer code, and call Dispose on all your objects rather than just letting them go out of scope.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Assuming you've copied the file, are you sure it's being copied synchronously and the operation completed?
If you're using some sort of stream writer to write the data into the new file, you need to make sure the stream has been flushed/closed/disposed.
As for disposal, the same goes for any other instances you've created that implement IDisposable. If you can (if they're not used further down the line), make sure that they are disposed (with a using statement or calling the Dispose method).
|
|
|
|