Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to read the values from the object variable in C#
    text
    copied!<p>I need to read the values from a variable which is of type <code>object</code> for e..g.., i have a variable called result as:</p> <pre><code>object result= h[key]; </code></pre> <p><code>h[key]</code> is a hash table which returns 5 values to result variable. How do I read the 1st value to my local variable of type string in C# script in SSIS package?</p> <p>I can see only <code>GetType</code>, <code>Equals</code>, <code>ToString()</code> options for result variable.</p> <p>Any help please?</p> <p>there is the sample:</p> <p>there is a sample; public void SQLLoop() { string bp,ap,ep,s,vs; LocationInfo info = new LocationInfo(); string connection = "Server=Sname;Database=Dname;Integrated Security=SSPI"; SqlConnection conn = new SqlConnection(connection);</p> <pre><code> conn.Open(); SqlCommand sqlcmd = new SqlCommand("SELECT Bp,Ap,EP,SL,VSr from Table1", conn); SqlDataReader rs=sqlcmd.ExecuteReader(); while (rs.Read()) { bp = rs.GetValue(0).ToString(); ap = rs.GetValue(1).ToString(); ep = rs.GetValue(2).ToString(); s = rs.GetValue(3).ToString(); vs = rs.GetValue(4).ToString(); info.loadLocationInfo(ap, bp, ep, s, vs); h.Add(s, info); } conn.Close(); } public class LocationInfo { String A; String B; String E; String S; String V; int id; public LocationInfo() { } public void loadLocationInfo(String a,String b,String e,String s,String v) { A =a ; B =b ; E=e ; S =s; V = v; } } </code></pre> <p>now </p> <p>public void fun1() { var result = (object )h[subject]; ///read values from the hash table</p> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload