PC Review


Reply
Thread Tools Rate Thread

C# newbie part2

 
 
Craig
Guest
Posts: n/a
 
      19th Sep 2005
I mixed up things in the previous post, sorry about that

I was looking for the equivalents in C#

1) Dim myRow As DataRow
For Each myRow In DataSetGroupSQL1.tblProfileGroups.Rows
'Test for ALL group
If myRow("GroupName") = "ALL" Then blnGroupALL = True
Next


2) With DataSetThoughtsForm1.tblYourThoughts(0)
.ProfileID = Session("UserID")
.ThoughtName = txtThoughtName.Text
.ThoughtText = txtThoughtText.Text
End With



 
Reply With Quote
 
 
 
 
=?Utf-8?B?VGF5bG9yTWljaGFlbEw=?=
Guest
Posts: n/a
 
      19th Sep 2005
For the general solution it is similar to VB:

foreach (DataRow myRow in DataSetGroupSQL1.tblProfileGroups.Rows)
{
//Do logic here, myRow is readonly
if (myRow("GroupName") = "ALL")
bInGroupAll = true;
};

When you need to write to an element then use a for loop instead.

For your specific case of a DataSet however I'd use the following faster
logic (the var assignment is simply for clarity, I'd combine the 2 statements
into 1):

DataRow[] rows = DataSetGroupSQL1.tblProfileGroups.Select("GroupName =
'ALL'");
bInGroupAll = (rows.Length > 0);

Michael Taylor - 9/19/05

"Craig" wrote:

> I mixed up things in the previous post, sorry about that
>
> I was looking for the equivalents in C#
>
> 1) Dim myRow As DataRow
> For Each myRow In DataSetGroupSQL1.tblProfileGroups.Rows
> 'Test for ALL group
> If myRow("GroupName") = "ALL" Then blnGroupALL = True
> Next
>
>
> 2) With DataSetThoughtsForm1.tblYourThoughts(0)
> .ProfileID = Session("UserID")
> .ThoughtName = txtThoughtName.Text
> .ThoughtText = txtThoughtText.Text
> End With
>
>
>
>

 
Reply With Quote
 
Christof Nordiek
Guest
Posts: n/a
 
      19th Sep 2005
"TaylorMichaelL" <(E-Mail Removed)> schrieb im
Newsbeitrag news:50205129-80BA-4192-80B8-(E-Mail Removed)...
> For the general solution it is similar to VB:
>
> foreach (DataRow myRow in DataSetGroupSQL1.tblProfileGroups.Rows)
> {
> //Do logic here, myRow is readonly
> if (myRow("GroupName") = "ALL")

that's wrong, should be:
if (myRow["GroupName"] == "ALL")
> bInGroupAll = true;
> };
>
> When you need to write to an element then use a for loop instead.
>
> For your specific case of a DataSet however I'd use the following faster
> logic (the var assignment is simply for clarity, I'd combine the 2
> statements
> into 1):
>
> DataRow[] rows = DataSetGroupSQL1.tblProfileGroups.Select("GroupName =
> 'ALL'");
> bInGroupAll = (rows.Length > 0);
>
> Michael Taylor - 9/19/05
>
> "Craig" wrote:
>
>> I mixed up things in the previous post, sorry about that
>>
>> I was looking for the equivalents in C#
>>
>> 1) Dim myRow As DataRow
>> For Each myRow In DataSetGroupSQL1.tblProfileGroups.Rows
>> 'Test for ALL group
>> If myRow("GroupName") = "ALL" Then blnGroupALL = True
>> Next
>>
>>
>> 2) With DataSetThoughtsForm1.tblYourThoughts(0)
>> .ProfileID = Session("UserID")
>> .ThoughtName = txtThoughtName.Text
>> .ThoughtText = txtThoughtText.Text
>> End With
>>
>>
>>
>>



 
Reply With Quote
 
Morten Wennevik
Guest
Posts: n/a
 
      19th Sep 2005
Hi Craig,

1) foreach(DataRow myRow in DataSetGroupSQL1.tblProfileGroups.Rows)
{
if(myRow["GroupName"].ToString() == "All")
blnGroupALL = true;
}

2) No equivalent, you ned to set each property using the full name:

DataSetThoughtsForm1.tblYourThoughts[0].ProfileID = (int)Session["UserID"];
DataSetThoughtsForm1.tblYourThoughts[0].txtThoughtName = txtThoughtName.Text;
DataSetThoughtsForm1.tblYourThoughts[0].txtThoughtText = txtThoughtText.Text;

Note that type conversion is much stricter in C#. Where VB.Net uses () for indexing, C# uses [].



On Mon, 19 Sep 2005 12:52:40 +0200, Craig <(E-Mail Removed)> wrote:

> I mixed up things in the previous post, sorry about that
>
> I was looking for the equivalents in C#
>
> 1) Dim myRow As DataRow
> For Each myRow In DataSetGroupSQL1.tblProfileGroups.Rows
> 'Test for ALL group
> If myRow("GroupName") = "ALL" Then blnGroupALL = True
> Next
>
>
> 2) With DataSetThoughtsForm1.tblYourThoughts(0)
> .ProfileID = Session("UserID")
> .ThoughtName = txtThoughtName.Text
> .ThoughtText = txtThoughtText.Text
> End With
>
>
>
>




--
Happy coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
Morten Wennevik
Guest
Posts: n/a
 
      19th Sep 2005
Hi Craig,

1) foreach(DataRow myRow in DataSetGroupSQL1.tblProfileGroups.Rows)
{
if(myRow["GroupName"].ToString() == "All")
blnGroupAll = true;
}

2) No equivalent, you need to set all properties individually

DataSetThoughtsForm1.tblYourThoughts(0).ProfileID = (int)Session["UserID"];
DataSetThoughtsForm1.tblYourThoughts(0).ThoughtName = txtThoughtName.Text;
DataSetThoughtsForm1.tblYourThoughts(0).ThoughtText = txtThoughtText.Text;

Note that type conversion is much stricter in C#.


On Mon, 19 Sep 2005 12:52:40 +0200, Craig <(E-Mail Removed)> wrote:

> I mixed up things in the previous post, sorry about that
>
> I was looking for the equivalents in C#
>
> 1) Dim myRow As DataRow
> For Each myRow In DataSetGroupSQL1.tblProfileGroups.Rows
> 'Test for ALL group
> If myRow("GroupName") = "ALL" Then blnGroupALL = True
> Next
>
>
> 2) With DataSetThoughtsForm1.tblYourThoughts(0)
> .ProfileID = Session("UserID")
> .ThoughtName = txtThoughtName.Text
> .ThoughtText = txtThoughtText.Text
> End With
>
>
>
>




--
Happy coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
Christof Nordiek
Guest
Posts: n/a
 
      19th Sep 2005

"Morten Wennevik" <(E-Mail Removed)> schrieb im Newsbeitrag
newsp.sxckyllzklbvpo@stone...
<snip>
> 2) No equivalent, you need to set all properties individually
>
> DataSetThoughtsForm1.tblYourThoughts(0).ProfileID =
> (int)Session["UserID"];
> DataSetThoughtsForm1.tblYourThoughts(0).ThoughtName = txtThoughtName.Text;
> DataSetThoughtsForm1.tblYourThoughts(0).ThoughtText = txtThoughtText.Text;
>

<snip>
Better is:
tblYourThoughtsRow row = DataSetThoughtsForm1.tblYourThoughts[0];
row.ProfileID = (int)Session["UserID"];
row.ThoughtName = txtThoughtName.Text;
row.ThoughtText = txtThoughtText.Text;

where tblYourThoughtsRow is the type of
DataSetThoughtsForm1.tblYourThought[0].


 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      19th Sep 2005
Craig wrote:
> I mixed up things in the previous post, sorry about that
>
> I was looking for the equivalents in C#
>
> 1) Dim myRow As DataRow
> For Each myRow In DataSetGroupSQL1.tblProfileGroups.Rows
> 'Test for ALL group
> If myRow("GroupName") = "ALL" Then blnGroupALL = True
> Next
>


In addidtion to the other answers: if "blnGroupALL" is you function name,
then you should use "return true;". In VB you assign the return value to
the function, in C# you use the "return" statement to return a value
(and immediately stop executing this method)

Hans Kesting


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Part2 When You Can Really Say B***** nivrip General Discussion 0 16th Jun 2008 09:57 PM
Part2 csv to xml rodchar Microsoft VB .NET 2 13th Jun 2008 01:13 AM
im being hacked again (part2) swoles Microsoft Access 0 28th Apr 2008 11:51 PM
newbie question - part2 Luminal Microsoft Dot NET Compact Framework 1 6th Sep 2004 08:33 PM
tabname=A2 (part2) Jean-Paul De Winter Microsoft Excel Misc 2 6th Apr 2004 11:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:44 AM.