While it's not impossible - or even difficult to return a class instead of a DataTable, it's not something that we can help you with, and that you need to think about fairly carefully.
First off: A DataTable isn't a single item of data, while the class you describe is:
Quote:
i want to do class with properties then return the class back
A class is easy:
public class MyClass
{
public int ID { get; set; }
public string UserName { get; set; }
public string UserType { get; set; }
}
Create an instance in your method, fill out the details, and return it.
But a DataTable contains data about many rows: so you probably don't want your method to return "a class", but a Collection of classes: perhaps a List<MyClass>
Think about what exactly you are trying to do, and what your DataTable currently contains, and it should be pretty trivial for you to construct the appropriate class, and return it or a collection of it.
But we can't do that for you!
Quote:
the normal code is doing the following :
public static DataTable GetSend(string IP, string User)
{
string sSql "some query with join";
if (User != string.Empty)
{
sSQL += " and CrtUser = '" + User + "'";
}
Don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;
Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
DROP TABLE MyTable;
A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
And that code is useless to us: we still have no idea what is in the DataTable, so we still can't help you.