473,440 Members | 1,731 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,440 software developers and data experts.

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.Length !=0)

{

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

{

if ( iIndex != 0 )

sSelect += " OR ";

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

}

DataRow[] FGrows = db.dataSetUsers.FunctionsGroups.Select(sSelect);
foreach (DataSetUsers.FunctionsGroupsRow row in FGrows)

{

DataSetUsers.FunctionsRow function =

db.dataSetUsers.Functions.FindByFunctionID( row.FunctionID );

name = function.Name ;

}

}

}

return name;

}
Nov 17 '05 #1
4 3805
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*********@luatech.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.Length !=0)

{

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

{

if ( iIndex != 0 )

sSelect += " OR ";

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

}

DataRow[] FGrows = db.dataSetUsers.FunctionsGroups.Select(sSelect);
foreach (DataSetUsers.FunctionsGroupsRow row in FGrows)

{

DataSetUsers.FunctionsRow function =

db.dataSetUsers.Functions.FindByFunctionID( 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*****@despammed.com> wrote in message
news:uP*************@TK2MSFTNGP10.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*********@luatech.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.Length !=0)

{

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

{

if ( iIndex != 0 )

sSelect += " OR ";

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

}

DataRow[] FGrows = db.dataSetUsers.FunctionsGroups.Select(sSelect);
foreach (DataSetUsers.FunctionsGroupsRow row in FGrows)

{

DataSetUsers.FunctionsRow function =

db.dataSetUsers.Functions.FindByFunctionID( 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[] GetFirstColFromSql(cmdText);

{

System.Data.SqlClient.SqlConnection conn=this.GetOpenConnection();

System.Data.SqlClient.SqlCommand sqlCommand=new
System.Data.SqlClient.SqlCommand(cmdText, conn);

System.Data.SqlClient.SqlDataReader
r=sqlCommand.ExecuteReader(System.Data.CommandBeha vior.Default);

String tmpString="";

while (r.Read())

{

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

}

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

r.Close();

conn.Close();

return resultArray;

}

"Hrvoje Voda" <hr*********@luatech.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*****@despammed.com> wrote in message
news:uP*************@TK2MSFTNGP10.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*********@luatech.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.Length !=0)

{

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

{

if ( iIndex != 0 )

sSelect += " OR ";

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

}

DataRow[] FGrows = db.dataSetUsers.FunctionsGroups.Select(sSelect);
foreach (DataSetUsers.FunctionsGroupsRow row in FGrows)

{

DataSetUsers.FunctionsRow function =

db.dataSetUsers.Functions.FindByFunctionID( row.FunctionID );

name = function.Name ;

}

}

}

return name;

}



Nov 17 '05 #4
Nathan Kovac <na**@tctelco.net> 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.ToString(r.Value(0));
}
string[] resultArray=tmpString.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.com>
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
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 *...
7
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...
4
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...
22
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
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...
14
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...
8
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...
17
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...
11
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 ...
14
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.
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.