SqlParameter Problem...

Results 1 to 2 of 2

Thread: SqlParameter Problem...

  1. #1
    Join Date
    Dec 1969

    Default SqlParameter Problem...

    I am creating a command object dynamically to run a stored procedure.The user passes name, type, value, direction etc. of the parameters that the stored procedure takes. Below is the function which is performing this.<BR><BR><BR>public static DataSet GetData(string strConnectionString,string SPName,string[] arrIParam,string[] arrIParamType,int[] arrIParamSize,int[] arrIParamOrder,string[] arrParamDir,string[] arrValue)<BR> {<BR> SqlCommand oCommand=new SqlCommand(SPName,Dal_DatabaseGeneral.getConnectio n(strConnectionString));<BR> oCommand.CommandText=SPName;<BR> oCommand.CommandType=CommandType.StoredProcedure;< BR> if(arrIParam!=null)<BR> {<BR> int paramCount,i;<BR> paramCount=arrIParam.Length;<BR> string SqlType;<BR> for(i=0;i&#060;paramCount;i++)<BR> {<BR><BR> //The function Bll_ConnectionString.GetSqlDbType(arrIParamType[i]) returns SqlDbType.Int for Int and so on...<BR><BR><BR> SqlType=Bll_ConnectionString.GetSqlDbType(arrIPara mType[i]);<BR> if(arrParamDir[i]=="Input")<BR> { <BR> oCommand.Parameters.Add(new SqlParameter(arrIParam[i],SqlType));<BR> oCommand.Parameters[arrIParam[i]].Value=arrValue[i];<BR> }<BR> else<BR> {<BR> oCommand.Parameters.Add(new SqlParameter(arrIParam[i],SqlType));<BR> oCommand.Parameters[arrIParam[i]].Direction=ParameterDirection.Output;<BR> }<BR> }<BR> }<BR><BR> return Dal_DatabaseGeneral.GetDataSetFromStoredProcedureH elp(SPName,oCommand,strConnectionString); <BR> }<BR><BR><BR>My Problem is when I pass the datatype of the SqlParameter, it goes as "SqlDbType.Int" whereas it should be SqlDbType.Int .<BR>Because of the quotes all the datatypes are taken as NVarchar.<BR><BR>Is there a way that I can pass the parameter type properly.<BR><BR>Thanx,<BR>Sweta<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: SqlParameter Problem...

    you should be using the [code language="C#"]SqlDbType[/code] data type rather than the string data type for your arguments ([code language="C#"]arrIParamType[/code]) and your [code language="C#"]SqlType[/code] variable ([code language="C#"]string SqlType[/code]).<BR><BR>If you didn&#039;t implement the GetSqlDbType function and it returns string, then you need to use reflection to figure out what the value is of the SqlDbType enumeration that corresponds to the value you&#039;re receiving as a string.<BR><BR>Kelly

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts