Last post Nov 23, 2018 07:03 PM by PatriceSc
Nov 23, 2018 04:10 AM|LiarLiarPantsOnFire|LINK
Hello - I am using a Asp.net web api to send data from an app to the API and insert into sql server.
This is DDL of my table, and my stored procedure that I am attempting to execute as well as the format of the data that is being sent. The issue is that I am attempting to assign a string value and I need to convert the string value to a binary(64) value
before it hits the stored procedure. How do I do this?
--URL being sent to API
CREATE TABLE [dbo].[data1](
[ID] [int] IDENTITY(1,1) NOT NULL,
[badgeIn] [varchar](100) NOT NULL,
[supIn] [varchar](100) NOT NULL,
[phone] [varchar](10) NULL,
[lsc] [varchar](100) NOT NULL,
[email] [varchar](100) NOT NULL,
[gona] [binary](64) NOT NULL
PRIMARY KEY CLUSTERED
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
SET IDENTITY_INSERT [dbo].[data1] ON
INSERT [dbo].[data1] ([ID], [badgeIn], [supIn], [phone], [lsc], [email], [gona]) VALUES (1, N'R183', N'TX1384', N'5555555555', N'Test', Nfirstname.lastname@example.org', 0x477265656E0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
SET IDENTITY_INSERT [dbo].[data1] OFF
ALTER PROCEDURE [dbo].[InsertData] @badgeIn varchar(100), @supIn varchar(100), @Phone varchar(100), @lsc varchar(100), @Email varchar(100), @gona binary(64)
INSERT INTO dbo.appinfo (badgeIn, supIn, phone, lsc, email, gona) VALUES (@badgeIn, @supIn, @Phone, @lsc, @Email, @gona)
Nov 23, 2018 07:03 PM|PatriceSc|LINK
You have multiple ways to do that and it depends on your intent. I suppose you don't want to just take the underlying ascii or unicode binary values for your "123" characters ?
If taking things the other way round I would use a base64 string or an hexadecimal string to represent a series of bytes as a string.
Edit: checked with your sample which is "Green". So it seems you want : https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytes?view=netframework-4.7.2#System_Text_Encoding_GetBytes_System_String_
Why don't you just store a string ?