Reputation: 7600
I am trying to convert the dataset item into the string and save into the array. But it gives me syntax error. Please help me out. This in VS 2005 and C#
Thanks in advance!!
string strdetailID[] = new string[4];
for(int i = 0; i < x ; i++)
{
strdetailID[i] = dsImages.Tables[0].Rows[i]["Ad_detailsID"].ToString();
}
Upvotes: 3
Views: 32201
Reputation: 1203
It is possible to size array before for each loop and form array directly without list.
string [] strDetailID = new string[dsImages.Tables[0].Rows.Count];
int arryIndex = 0;
foreach(DataRow row in dsImages.Tables[0].Rows)
{
strDetailID [arryIndex] = row["Ad_detailsID"].ToString());
arryIndex++;
}
Upvotes: 0
Reputation: 1
string[] strdetailID = new string[4];
for(int i = 0; i < x ; i++)
{
strdetailID[i] = dsImages.Tables[0].Rows[i]["Ad_detailsID"].ToString();
}
This will work ..you made a mistake string strdetailID[]
Upvotes: 0
Reputation:
List<string> strDetailIDList = new List<string>();
foreach(DataRow row in dsImages.Tables[0].Rows)
{
strDetailIDList.Add(row["Ad_detailsID"].ToString());
}
string strDetailID[] = strDetailIDList.ToArray();
I have used a List<string>
instead of a string
array, as I think it would be easier to dynamically add elements, but if you want to still use a string
array, you should get the general idea.
Upvotes: 5