Hi ,
I am trying to write a piece of funtionality that will store a string array into
into a database and then later retrieve it for viewing later.
I wrote the funtionality to insert the string array into the database (stored it the datatype 'image' in the database). But can't figure out how to retrieve the data now .
When i viewed the string it wrote into the table using the select query in sql server 2005 it looked like this "0x53797374656D 2E537472696E675 B5D". But I guessed that its normal as it has been stored as an object.
Below given is the code i wrote to retrieve the string array from the database ,
i have commented where I am having the problem
SqlConnection n = new SqlConnection() ;
n.ConnectionStr ing = "Data Source=JAKE-19812CE655\\SQL EXPRESS;Initial Catalog=monitor ing;Integrated Security=True";
SqlCommand m = new SqlCommand();
m.CommandText = "select CPU_usage from processes where process_id = '1'";
m.Connection = n;
SqlDataReader j;
n.Open();
j = m.ExecuteReader ();
n.Close();
while(j.Read())
{
object w = j["cpu_usage"]; // this is where the problem is ,
the value can only be retrieved from the database as an object , i want it
to retrieve it back as a string array , just like the way i wrote it into the datbase
....any way i can do that ?
}
I am trying to write a piece of funtionality that will store a string array into
into a database and then later retrieve it for viewing later.
I wrote the funtionality to insert the string array into the database (stored it the datatype 'image' in the database). But can't figure out how to retrieve the data now .
When i viewed the string it wrote into the table using the select query in sql server 2005 it looked like this "0x53797374656D 2E537472696E675 B5D". But I guessed that its normal as it has been stored as an object.
Below given is the code i wrote to retrieve the string array from the database ,
i have commented where I am having the problem
SqlConnection n = new SqlConnection() ;
n.ConnectionStr ing = "Data Source=JAKE-19812CE655\\SQL EXPRESS;Initial Catalog=monitor ing;Integrated Security=True";
SqlCommand m = new SqlCommand();
m.CommandText = "select CPU_usage from processes where process_id = '1'";
m.Connection = n;
SqlDataReader j;
n.Open();
j = m.ExecuteReader ();
n.Close();
while(j.Read())
{
object w = j["cpu_usage"]; // this is where the problem is ,
the value can only be retrieved from the database as an object , i want it
to retrieve it back as a string array , just like the way i wrote it into the datbase
....any way i can do that ?
}
Comment