setting timestamp parameter

  • Thread starter Thread starter Eirik M.
  • Start date Start date
E

Eirik M.

What is the correct way to set the value of an SqlParameter of
SqlDbType.Timestamp? Let's say you've got the following declaration

SqlParameter[] parms = {
new SqlParameter ("@PKId", SqlDbType.Int),
new SqlParameter ("@description", SqlDbType.NVarChar),
new SqlParameter ("@timestamp", SqlDbType.Timestamp) //Vs.Net uses
SqlDbType.VarBinary
};

and

foreach (DataRow r in data.Tables[0].Rows) {
parms[0].Value = r[0]; // PKId - >int
parms[1].Value = r[1]; // description -> string
parms[2].Value = r[2]; // timestamp -> string?
StoredProcedure sp = new StoredProcedure ("UpdatetableWithTS", parms,
conn);
i += sp.Run ();
}

When the code above gets executed I get the following exception "Invalid
cast from System.String to System.Byte[]."
So how do I go about it?

E.M.
 
Found the solution.
parms[2].Value = Convert.FromBase64String(r[2].ToString());

E.M.
 
Back
Top