473,791 Members | 2,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string array

How to get a list of names from database into string array?

variable name should be string array...

This is the code I use...

public string GetFunctionName (Guid UserID)

{
sSelect = "";

string name="";

if (db!=null)

{
if (nGroupID.Lengt h !=0)

{

for ( int iIndex = 0; iIndex < nGroupID.Length ; iIndex++ )

{

if ( iIndex != 0 )

sSelect += " OR ";

sSelect += "GroupID ='" + nGroupID[ iIndex ].ToString () + "'";

}

DataRow[] FGrows = db.dataSetUsers .FunctionsGroup s.Select(sSelec t);
foreach (DataSetUsers.F unctionsGroupsR ow row in FGrows)

{

DataSetUsers.Fu nctionsRow function =

db.dataSetUsers .Functions.Find ByFunctionID( row.FunctionID );

name = function.Name ;

}

}

}

return name;

}
Nov 17 '05 #1
4 3820
Once you concatonate the names in a string, you could just use string split
method and it would create an array for you, or add an iterator to your
foreach and add them directly to a string array.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Hrvoje Voda" <hr*********@lu atech.com> wrote in message
news:d8******** **@ss405.t-com.hr...
How to get a list of names from database into string array?

variable name should be string array...

This is the code I use...

public string GetFunctionName (Guid UserID)

{
sSelect = "";

string name="";

if (db!=null)

{
if (nGroupID.Lengt h !=0)

{

for ( int iIndex = 0; iIndex < nGroupID.Length ; iIndex++ )

{

if ( iIndex != 0 )

sSelect += " OR ";

sSelect += "GroupID ='" + nGroupID[ iIndex ].ToString () + "'";

}

DataRow[] FGrows = db.dataSetUsers .FunctionsGroup s.Select(sSelec t);
foreach (DataSetUsers.F unctionsGroupsR ow row in FGrows)

{

DataSetUsers.Fu nctionsRow function =

db.dataSetUsers .Functions.Find ByFunctionID( row.FunctionID );

name = function.Name ;

}

}

}

return name;

}

Nov 17 '05 #2
I'm not that good in c#, can you give me some example?


"John Timney (ASP.NET MVP)" <ti*****@despam med.com> wrote in message
news:uP******** *****@TK2MSFTNG P10.phx.gbl...
Once you concatonate the names in a string, you could just use string
split method and it would create an array for you, or add an iterator to
your foreach and add them directly to a string array.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Hrvoje Voda" <hr*********@lu atech.com> wrote in message
news:d8******** **@ss405.t-com.hr...
How to get a list of names from database into string array?

variable name should be string array...

This is the code I use...

public string GetFunctionName (Guid UserID)

{
sSelect = "";

string name="";

if (db!=null)

{
if (nGroupID.Lengt h !=0)

{

for ( int iIndex = 0; iIndex < nGroupID.Length ; iIndex++ )

{

if ( iIndex != 0 )

sSelect += " OR ";

sSelect += "GroupID ='" + nGroupID[ iIndex ].ToString () + "'";

}

DataRow[] FGrows = db.dataSetUsers .FunctionsGroup s.Select(sSelec t);
foreach (DataSetUsers.F unctionsGroupsR ow row in FGrows)

{

DataSetUsers.Fu nctionsRow function =

db.dataSetUsers .Functions.Find ByFunctionID( row.FunctionID );

name = function.Name ;

}

}

}

return name;

}


Nov 17 '05 #3
I am not totally clear what your doing in your code and what you want to do
so I am going to show you a fresh example of how I would do what the
previous guy mentioned.

Keep in mind I didn't understand your example and you may already have a
loop set up to go through the records and the last 2 lines is probably what
you need. Also note I haven't tested this code, but it should work with a
little debugging.

private string[] GetFirstColFrom Sql(cmdText);

{

System.Data.Sql Client.SqlConne ction conn=this.GetOp enConnection();

System.Data.Sql Client.SqlComma nd sqlCommand=new
System.Data.Sql Client.SqlComma nd(cmdText, conn);

System.Data.Sql Client.SqlDataR eader
r=sqlCommand.Ex ecuteReader(Sys tem.Data.Comman dBehavior.Defau lt);

String tmpString="";

while (r.Read())

{

tmpString+="|"+ Convert.ToStrin g(r.Value(0));

}

string[] resultArray=tmp String.Split('| ');

r.Close();

conn.Close();

return resultArray;

}

"Hrvoje Voda" <hr*********@lu atech.com> wrote in message
news:d8******** **@ss405.t-com.hr...
I'm not that good in c#, can you give me some example?


"John Timney (ASP.NET MVP)" <ti*****@despam med.com> wrote in message
news:uP******** *****@TK2MSFTNG P10.phx.gbl...
Once you concatonate the names in a string, you could just use string
split method and it would create an array for you, or add an iterator to
your foreach and add them directly to a string array.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Hrvoje Voda" <hr*********@lu atech.com> wrote in message
news:d8******** **@ss405.t-com.hr...
How to get a list of names from database into string array?

variable name should be string array...

This is the code I use...

public string GetFunctionName (Guid UserID)

{
sSelect = "";

string name="";

if (db!=null)

{
if (nGroupID.Lengt h !=0)

{

for ( int iIndex = 0; iIndex < nGroupID.Length ; iIndex++ )

{

if ( iIndex != 0 )

sSelect += " OR ";

sSelect += "GroupID ='" + nGroupID[ iIndex ].ToString () + "'";

}

DataRow[] FGrows = db.dataSetUsers .FunctionsGroup s.Select(sSelec t);
foreach (DataSetUsers.F unctionsGroupsR ow row in FGrows)

{

DataSetUsers.Fu nctionsRow function =

db.dataSetUsers .Functions.Find ByFunctionID( row.FunctionID );

name = function.Name ;

}

}

}

return name;

}



Nov 17 '05 #4
Nathan Kovac <na**@tctelco.n et> wrote:
I am not totally clear what your doing in your code and what you want to do
so I am going to show you a fresh example of how I would do what the
previous guy mentioned.

Keep in mind I didn't understand your example and you may already have a
loop set up to go through the records and the last 2 lines is probably what
you need. Also note I haven't tested this code, but it should work with a
little debugging.
<snip>
while (r.Read())

{
tmpString+="|"+ Convert.ToStrin g(r.Value(0));
}
string[] resultArray=tmp String.Split('| ');
r.Close();
conn.Close();
return resultArray;


There's no point in putting everything into a string and then splitting
it up again.

Just use an ArrayList, and entries to that in the while loop. If an
array is required afterwards, you can then call ToArray(typeof( string))
on the ArrayList and cast to string[].

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
17503
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char * is 4 bytes, should the following yield 4, 5, of something else? (And, if something else, what determines the result?) char x = "abcd"; printf( "%d\n", sizeof( x ) ); -Don
7
4366
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have type of "const char *". Right? But why does the compiler I am using allow s to be modified, instead of generating compile error?
4
5399
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string literal. But the second printf seems to give me garbage. Any advise on what I am doing wrong? Thanx
22
17204
by: spike | last post by:
How do i reset a string? I just want to empty it som that it does not contain any characters Say it contains "hello world" at the time... I want it to contain "". Nothing that is.. Thanx
4
8827
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where a * occurs in the string). This split function should allocate a 2D array of chars and put the split results in different rows. The listing below shows how I started to work on this. To keep the program simple and help focus the program the...
14
15052
by: Bob | last post by:
I have a function that takes in a list of IDs (hundreds) as input parameter and needs to pass the data to another step as a comma delimited string. The source can easily create this list of IDs in a comma-delimited string or string array. I don't want it to be a string because I want to overload this function, and it's sister already uses a string input parameter. Now if I define the function to take in a string array, it solves my...
8
13951
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of the array can vary depending on the parameters passed. What I need to do is loop through the returned array and if applicable write the array element to the screen.
17
4673
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some analysis and I'm led to believe (but can't yet quantitatively establish as fact) that the two basic culprits are a lot of calls to: 1.) if( someString.ToLower() == "somestring" ) and
11
17654
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer s(i)=new string(test) Above line gives - error implicit conversion string to 1-dim array of
14
4094
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10154
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.