Saturday, March 31, 2012

string to string[]

Hi,

I've got this code :


string[] Params;

string SQL = "SELECT * FROM T_MANAGEMENT_PAGES";
SqlCommand myCommand = new SqlCommand(SQL, myConnection);
myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader();

try
{
while (myReader.Read())
{
Params_Type = myReader.GetValue(0).ToString();
}
}
catch
{
}
finally
{
}
myReader.Close();

My problem is to obtain Params_Type.
But each time, it says : "impossible to convert '[object]' in 'string[]' "

Thanks for all.
SébHello, try this instead:


int i = 0;
while (myReader.Read())
{
Params_Type[i] = myReader.GetValue(0).ToString();
i++;
}

Hope this works fine for u.
Yes but, in my database I have in one column :
{"BURE_ETUD_ID","LANG_ID","LANG_NAME"}

My sql return only one line.

and what I want is :


string[] Params = {"BURE_ETUD_ID","LANG_ID","LANG_NAME"};

Thanks
Séb
You should, ideally, rework your database. This is not a great layout. You should have a table that links to this record and has one row per entry to allow you to better get at the data.

Given the string returned as it is, you could use String.Split() to create a string array.
I Agree with you, but is there any possibility to convert one string in one string[] ?

Séb
Yes. As I mentioned in my last post: the String class has a Split() method. Please look at the docs.
I'm sorry, i haven't see the end of your message.

Thanks for your heulp

Regards

Séb
Hello,
I believe yes, you should rework ur database, each value should be in one column. this is typical !!!
then, after u rework ur database, use the code i gave, it works just fine.

Good Luck.

0 comments:

Post a Comment