setting timestamp parameter

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.
 
E

Eirik M.

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

E.M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top