Casting - IDataParameter

  • Thread starter Thread starter Doug
  • Start date Start date
D

Doug

Is there some way to cast a IDataParameter to a SQLParameter? It's not
working and I'm not sure why.
 
Hi

That works perfect for me:

using System;
using System.Data;
using System.Data.SqlClient;
using NUnit.Framework;

namespace myNameSpace
{
[TestFixture]
public class TestCasting
{
[Test]
public void CastIDataParameter()
{
IDataParameter param = new SqlParameter("myParamName", true);
SqlParameter castedParam = (param as SqlParameter);

Assert.AreEqual("myParamName", castedParam.ParameterName);
Assert.AreEqual(true, castedParam.Value);

Assert.AreEqual("myParamName", param.ParameterName);
Assert.AreEqual(true, param.Value);
}
}
}

Greetings from Switzerland
Thomas
 
I decided not to use the IDataParameter object and went with using the
SqlParameter object directly. I got rid of the code I had before that
wasn't working so unfortunately can't send it along, but I think it
might have been more of a problem with some common code I was trying to
use within our group. Thanks though!
 
Back
Top