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