Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 30, 2012 09:07 AM by vicky1
Member
32 Points
349 Posts
Nov 29, 2012 05:18 AM|LINK
Hi all,
i am converting one vb code to c#.
here is my vb code:
ddlEcat.SelectedValue = IIf(IsDBNull(objDs.Tables(0).Rows(0)("Emp_cat")), "-- Select --", objDs.Tables(0).Rows(0)("Emp_cat"))
here it's storing the data in drop downlist.
i tried to convert this code by developer fusion and got this code.
ddlEcat.SelectedValue = (Information.IsDBNull(objDs.Tables[0].Rows[0]["Emp_cat"]) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"]);
but getting error in information
here objds is object of dataset.
so it is checking if dataset is null then insert "select" or if dataset is not null it insert the value.
how to do this in C# correctly?
Star
13599 Points
2691 Posts
Nov 29, 2012 05:29 AM|LINK
Hi,
Additionally the
Iif function in VB.Net is weakly typed. It accepts and returns values typed as Object
The closest equivalent you can write is the following. Putting the values into the arguments forces the evaluation of their side effects.
public static object Iif(bool cond, object left, object right) { return cond ? left : right; }
Or slightly more usable
public static T Iif<T>(bool cond, T left, T right) { return cond ? left : right; }
Nov 29, 2012 05:32 AM|LINK
Hi sarathi,
thanks for response.
i didn't get much. could you plz set your logic to this code.
thanks
Nov 29, 2012 06:10 AM|LINK
The code you posted looking correct only, are you getting any error? I am away from my machine nto able to test it.
Try like the following
ddlEcat.SelectedValue = (Information.IsDBNull(objDs.Tables[0].Rows[0]["Emp_cat"].ToString()) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"].ToString());
Nov 29, 2012 07:05 AM|LINK
hi sarathi,
when i am pasting this code getting error in "Information" keyword.
it's saying information keyword does not exist in the current context.
Contributor
2170 Points
484 Posts
Nov 29, 2012 07:21 AM|LINK
Hi
Try this
import this namespace Using Microsoft.VisualBasic;
OR use System.DBNull
ddlEcat.SelectedValue = (System.DBNull(objDs.Tables[0].Rows[0]["Emp_cat"]) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"]);
Regards,
Charan
7983 Points
2099 Posts
Nov 29, 2012 07:28 AM|LINK
ddlEcat.SelectedValue = ( IsDBNull(objDs.Tables[0].Rows[0]["Emp_cat"]) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"] );
Nov 29, 2012 07:58 AM|LINK
hi,
i used this code: ddlEcat.SelectedValue = (System.DBNull(objDs.Tables[0].Rows[0]["Emp_cat"]) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"]);
but getting error: System.DBNull is a 'type' which is not valid in the given context.
Nov 29, 2012 08:00 AM|LINK
IsDBNull is not a keyword in C#.
Nov 29, 2012 08:17 AM|LINK
Sorry , Try this
ddlEcat.SelectedValue = ((objDs.Tables[0].Rows[0]["Emp_cat"]) == System.DBNull.Value ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"]);
vicky1
Member
32 Points
349 Posts
How to use this vb code in c#?
Nov 29, 2012 05:18 AM|LINK
Hi all,
i am converting one vb code to c#.
here is my vb code:
ddlEcat.SelectedValue = IIf(IsDBNull(objDs.Tables(0).Rows(0)("Emp_cat")), "-- Select --", objDs.Tables(0).Rows(0)("Emp_cat"))
here it's storing the data in drop downlist.
i tried to convert this code by developer fusion and got this code.
ddlEcat.SelectedValue = (Information.IsDBNull(objDs.Tables[0].Rows[0]["Emp_cat"]) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"]);
but getting error in information
here objds is object of dataset.
so it is checking if dataset is null then insert "select" or if dataset is not null it insert the value.
how to do this in C# correctly?
sarathi125
Star
13599 Points
2691 Posts
Re: How to use this vb code in c#?
Nov 29, 2012 05:29 AM|LINK
Hi,
Additionally the
. The C# ternary operator is strongly typed.The closest equivalent you can write is the following. Putting the values into the arguments forces the evaluation of their side effects.
Or slightly more usable
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
vicky1
Member
32 Points
349 Posts
Re: How to use this vb code in c#?
Nov 29, 2012 05:32 AM|LINK
Hi sarathi,
thanks for response.
i didn't get much. could you plz set your logic to this code.
ddlEcat.SelectedValue = (Information.IsDBNull(objDs.Tables[0].Rows[0]["Emp_cat"]) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"]);
thanks
sarathi125
Star
13599 Points
2691 Posts
Re: How to use this vb code in c#?
Nov 29, 2012 06:10 AM|LINK
Hi,
The code you posted looking correct only, are you getting any error? I am away from my machine nto able to test it.
Try like the following
ddlEcat.SelectedValue = (Information.IsDBNull(objDs.Tables[0].Rows[0]["Emp_cat"].ToString()) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"].ToString());
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
vicky1
Member
32 Points
349 Posts
Re: How to use this vb code in c#?
Nov 29, 2012 07:05 AM|LINK
hi sarathi,
when i am pasting this code getting error in "Information" keyword.
it's saying information keyword does not exist in the current context.
thanks
chaaraan
Contributor
2170 Points
484 Posts
Re: How to use this vb code in c#?
Nov 29, 2012 07:21 AM|LINK
Hi
Try this
import this namespace
Using Microsoft.VisualBasic;
ddlEcat.SelectedValue = (Information.IsDBNull(objDs.Tables[0].Rows[0]["Emp_cat"]) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"]);
OR use System.DBNull
ddlEcat.SelectedValue = (System.DBNull(objDs.Tables[0].Rows[0]["Emp_cat"]) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"]);
Regards,
Charan
RameshRajend...
Star
7983 Points
2099 Posts
Re: How to use this vb code in c#?
Nov 29, 2012 07:28 AM|LINK
ddlEcat.SelectedValue = ( IsDBNull(objDs.Tables[0].Rows[0]["Emp_cat"]) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"] );
vicky1
Member
32 Points
349 Posts
Re: How to use this vb code in c#?
Nov 29, 2012 07:58 AM|LINK
hi,
i used this code: ddlEcat.SelectedValue = (System.DBNull(objDs.Tables[0].Rows[0]["Emp_cat"]) ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"]);
but getting error: System.DBNull is a 'type' which is not valid in the given context.
thanks
vicky1
Member
32 Points
349 Posts
Re: How to use this vb code in c#?
Nov 29, 2012 08:00 AM|LINK
hi,
IsDBNull is not a keyword in C#.
thanks
chaaraan
Contributor
2170 Points
484 Posts
Re: How to use this vb code in c#?
Nov 29, 2012 08:17 AM|LINK
Sorry , Try this
ddlEcat.SelectedValue = ((objDs.Tables[0].Rows[0]["Emp_cat"]) == System.DBNull.Value ? "-- Select --" : objDs.Tables[0].Rows[0]["Emp_cat"]);
Regards,
Charan