Pls tell me, how to Pass DynamicParameterName, Value & its data type collection to DbCommand?
I have a method given below where I have to pass collection of dynamic parameter name, value and its type :
public DbCommand GetDataCommand(string strStoredProcName, DynamicParameterNameValueAndType paramNameValueType)
{
}
foreach values paramName in paramNameValueType, i have to get its value and Data type . so that I can add it input parameter to Database class of enterprise library.
Hi, I need to Write a Class or Inherit a Collection, to have ParameterName(@UserId),value(1),DataType(Int32) like wise.
I need to dynamically pass the ParameterName,value & DataType to that class/collection... so that I can use assign each of those item to DbCommand SP... any help?
Hi I am using Database class from Microsoft.Practices.EnterpriseLibarary.Data, like: Database db; db = DatabaseFactory.CreateDatabase(CONNSTRTAGNAME); THEN adding input parameter to this db object like given below which accepts 4 parameters mandatorarly.
cmayil
Member
60 Points
45 Posts
How to Pass DynamicParameterName, Value & its data type collection to DbCommand
Dec 17, 2012 05:52 PM|LINK
Hi All,
Pls tell me, how to Pass DynamicParameterName, Value & its data type collection to DbCommand?
I have a method given below where I have to pass collection of dynamic parameter name, value and its type :
public DbCommand GetDataCommand(string strStoredProcName, DynamicParameterNameValueAndType paramNameValueType)
{
}
foreach values paramName in paramNameValueType, i have to get its value and Data type . so that I can add it input parameter to Database class of enterprise library.
aptbid2002
Member
244 Points
52 Posts
Re: How to Pass DynamicParameterName, Value & its data type collection to DbCommand
Dec 17, 2012 05:59 PM|LINK
I've built a simular class that takes an array of IDataParameter, so when I pass parameters it looks like this:
dim spc() as sqlparameter = {new sqlparameter("@p1", value), new sqlparameter("@p2", value)}
command.parameters.addrange(spc)
hope that helps.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to Pass DynamicParameterName, Value & its data type collection to DbCommand
Dec 18, 2012 05:46 AM|LINK
What's that? I cannot find such a class existing in the MSDN.
cmayil
Member
60 Points
45 Posts
Re: How to Pass DynamicParameterName, Value & its data type collection to DbCommand
Dec 18, 2012 05:47 AM|LINK
Hey, I need to pass parameter name, value & its DataType as a collection to DbCommand not sqlcommand.
Any help?....
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to Pass DynamicParameterName, Value & its data type collection to DbCommand
Dec 18, 2012 05:50 AM|LINK
Hi again,
Can you tell us what is that class? I cannot find that in MSDN……:(
cmayil
Member
60 Points
45 Posts
Re: How to Pass DynamicParameterName, Value & its data type collection to DbCommand
Dec 18, 2012 06:51 AM|LINK
Hi, I need to Write a Class or Inherit a Collection, to have ParameterName(@UserId),value(1),DataType(Int32) like wise.
I need to dynamically pass the ParameterName,value & DataType to that class/collection... so that I can use assign each of those item to DbCommand SP... any help?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to Pass DynamicParameterName, Value & its data type collection to DbCommand
Dec 18, 2012 06:57 AM|LINK
In fact you can write a method like this:
public void ExecuteDynamic(string sql, param SqlParameter[]params)
{
………………
}
And you can call this:
ExecuteDynamic("insert into xxx values(@p1)", new SqlParameter[]{new SqlParameter{Name="@p1",Value=……});
Please do little modifications according to your own situation.
cmayil
Member
60 Points
45 Posts
Re: How to Pass DynamicParameterName, Value & its data type collection to DbCommand
Dec 18, 2012 10:02 AM|LINK
Hi I am using Database class from Microsoft.Practices.EnterpriseLibarary.Data, like: Database db; db = DatabaseFactory.CreateDatabase(CONNSTRTAGNAME); THEN adding input parameter to this db object like given below which accepts 4 parameters mandatorarly.
db.AddInParameter("SP Name", parameterName, DbType, value);
Here the problem is, I need to pass values dynamically for ParameterName,DbType & value all as collection, How can be this achieved?
I tried hastable, dictionary but I am able to pass only 2 parameters collection not 3. Is there any other alternative?
Pls help me on this.
cmayil
Member
60 Points
45 Posts
Re: How to Pass DynamicParameterName, Value & its data type collection to DbCommand
Dec 20, 2012 06:44 AM|LINK
Can someone help me on adding 3 variable to Collection object. eg: CustomDictionary.add(ParamName,ParamVal,DbType)
or CustomHashTable.Add(ParamName,ParamVal,DbType)... or any of the best way........?
Thanks in advance for your assistance.
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: How to Pass DynamicParameterName, Value & its data type collection to DbCommand
Dec 21, 2012 11:15 AM|LINK
Does this relate to ASP.Net Dynamic Data? as I have never heard of these type?
Always seeking an elegant solution.