1

Currently we are executing stored procedure with hex string from .NET

command.executequery("exec spname 
x092837x737")

No single quote in string parameter.

We want to change it to

command.text = "spname"
command.parameters.add("x09283x737")
command.executequery()

Problem here is .NET considering parameter as string but not actual hex. Is there a way we can add parameters like below

command.parameters.add(x09283x737)

Without double quote.

Is it possible in .NET

Harshal C
  • 7
  • 5
  • Try : SqlParameter parameter = new SqlParameter("spname", System.Data.SqlDbType.Int); SqlCommand cmd = new SqlCommand(); cmd.Parameters.Add(parameter); parameter.Value = 0x092837; – jdweng Aug 31 '22 at 11:28
  • Thanks for your reply but its not number its hex text, any other way – Harshal C Aug 31 '22 at 12:04
  • Than change type to varchar. – jdweng Aug 31 '22 at 12:05
  • Ya but value string 0x092837 getting compile time error in .net – Harshal C Aug 31 '22 at 12:27
  • Because when you change type to string you also have to put double quotes around the value. – jdweng Aug 31 '22 at 12:50
  • Yes that is the problem i am facing... What can be done on this..there is no data type i found in .net to handle this. – Harshal C Aug 31 '22 at 14:08
  • The System.Data.SqlDbType should match the type in the database. – jdweng Aug 31 '22 at 14:54
  • I am giving it NVarchar in database but its not able to find out if its string or hex – Harshal C Aug 31 '22 at 14:59
  • You have a string which is NVARCHAR. It is not hex if the database defines NVARCHAR. – jdweng Aug 31 '22 at 15:17
  • In sybase hex string can be assigned to nvarchar datatype like below Declare @data nvarchar = x097372 – Harshal C Aug 31 '22 at 15:22
  • It is not HEX. It is nvarchar which is a string.SqlParameter parameter = new SqlParameter("spname", System.Data.SqlDbType.NVarChar); SqlCommand cmd = new SqlCommand(); cmd.Parameters.Add(parameter); parameter.Value = "0x092837"; – jdweng Aug 31 '22 at 16:52

0 Answers0