Click here to Skip to main content
15,891,943 members
Home / Discussions / C#
   

C#

 
GeneralRe: i got some xml questions Pin
harold aptroot5-May-09 10:57
harold aptroot5-May-09 10:57 
AnswerRe: i got some xml questions Pin
led mike5-May-09 4:31
led mike5-May-09 4:31 
QuestionConvert Variant in VB to C# Pin
klaydze5-May-09 3:22
klaydze5-May-09 3:22 
AnswerRe: Convert Variant in VB to C# Pin
Le centriste5-May-09 5:19
Le centriste5-May-09 5:19 
GeneralRe: Convert Variant in VB to C# Pin
klaydze6-May-09 2:20
klaydze6-May-09 2:20 
QuestionVariant in VB to C# Pin
klaydze5-May-09 3:13
klaydze5-May-09 3:13 
AnswerRe: Variant in VB to C# Pin
Simon P Stevens5-May-09 4:39
Simon P Stevens5-May-09 4:39 
GeneralRe: Variant in VB to C# Pin
klaydze6-May-09 2:17
klaydze6-May-09 2:17 
Simon Stevens wrote:
A variant in VB is something that can be any type. The closest equivalent in C# is an 'Object'. In C# all data types derive from Object, so you can return the value as an Object and then cast it to what ever type it actually is.

(By the way, this is rather bad programming style, you should really be using parametrized queries, or stored procedures. This code is very vulnerable to SQL injection attacks. Also, by just chucking objects around everywhere you lose a lot of the benefits of strongly typed languages like C# such as compile time type checking. Also you seem to be repeating your select/case block about 3 times with the same code in it each time, it seems like you might have some redundant code here)


Hi Simon,

First, thanks for your reply.
I already converted my code to C#.Net. Yeah I used object as equivalent of variant.
My code something like this.

public object GetData(string SQL)
{
     DataTable DT = new DataTable();
     
     DT = dbConn.ExecuteQuery(SQL); dbConn is my connection class

     if (!String.IsNullOrEmpty(DT.Rows[0][0].ToString()))
     {
          switch (DT.Column[0].DataType.ToString())
          {
                case "System.ToInt32":
                    //Code
                    return;
                case "System.String":
                    //code
                    return;
          }
     }
}


Any piece of advise?

The code just get the 1 field value in the query. Just thinking this is the best way, the shortest way of getting the 1 value in a query.

Example:
string sName;
sName = GetData("Select txtFirstname From tblUsers Where intID = 1").ToString();


Regards,

klaydze

if(you type your code here) {
Messagebox.Show("You help me a lot!");
}
else {
You help me = null;
}

GeneralRe: Variant in VB to C# Pin
Simon P Stevens6-May-09 2:57
Simon P Stevens6-May-09 2:57 
GeneralRe: Variant in VB to C# Pin
klaydze6-May-09 3:51
klaydze6-May-09 3:51 
GeneralRe: Variant in VB to C# Pin
Simon P Stevens6-May-09 4:38
Simon P Stevens6-May-09 4:38 
GeneralRe: Variant in VB to C# Pin
klaydze6-May-09 4:58
klaydze6-May-09 4:58 
GeneralRe: Variant in VB to C# Pin
Simon P Stevens6-May-09 6:14
Simon P Stevens6-May-09 6:14 
GeneralRe: Variant in VB to C# Pin
klaydze7-May-09 3:44
klaydze7-May-09 3:44 
QuestionRich Text Box Flicker Pin
Paul Unsworth5-May-09 3:12
Paul Unsworth5-May-09 3:12 
AnswerRe: Rich Text Box Flicker Pin
Nuri Ismail5-May-09 5:45
Nuri Ismail5-May-09 5:45 
GeneralRe: Rich Text Box Flicker Pin
Paul Unsworth5-May-09 21:15
Paul Unsworth5-May-09 21:15 
QuestionCalling C# function in Java Pin
raesa5-May-09 1:40
raesa5-May-09 1:40 
AnswerRe: Calling C# function in Java Pin
Nagy Vilmos5-May-09 1:54
professionalNagy Vilmos5-May-09 1:54 
GeneralRe: Calling C# function in Java Pin
raesa5-May-09 2:02
raesa5-May-09 2:02 
GeneralRe: Calling C# function in Java Pin
Tom Deketelaere5-May-09 2:25
professionalTom Deketelaere5-May-09 2:25 
GeneralRe: Calling C# function in Java Pin
Nagy Vilmos5-May-09 2:29
professionalNagy Vilmos5-May-09 2:29 
QuestionProcess's changes Pin
lost_in_code5-May-09 1:09
lost_in_code5-May-09 1:09 
Questionc# socket server error Pin
Whydah5-May-09 0:49
Whydah5-May-09 0:49 
AnswerRe: c# socket server error Pin
stancrm5-May-09 2:09
stancrm5-May-09 2:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.