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;
}