Insert Data Into Binary(64) Column From Asp.Net API












0















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
XXX.XXX.XX.XXX:XXX/api/user/adduser?firstparam="a"&secparam="b"&thirparam="c"&fourparam="d"&fiveparam="e"&sixparam=123

--SQL DDL
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
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[data1] ON
GO
INSERT [dbo].[data1] ([ID], [badgeIn], [supIn], [phone], [lsc], [email], [gona]) VALUES (1, N'R183', N'TX1384', N'5555555555', N'Test', N'test1234@test.com', 0x477265656E0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
GO
SET IDENTITY_INSERT [dbo].[data1] OFF
GO

--Stored Proc
ALTER PROCEDURE [dbo].[InsertData] @badgeIn varchar(100), @supIn varchar(100), @Phone varchar(100), @lsc varchar(100), @Email varchar(100), @gona binary(64)

AS

INSERT INTO dbo.appinfo (badgeIn, supIn, phone, lsc, email, gona) VALUES (@badgeIn, @supIn, @Phone, @lsc, @Email, @gona)


EDIT

The error shown in my response variable is:




{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.NSUrlSessionHandler+NSUrlSessionDataTaskStreamContent, Headers:
{
Pragma: no-cache
X-Powered-By: ASP.NET
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
Date: Fri, 23 Nov 2018 13:32:43 GMT
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Content-Length: 36
Expires: -1
}}




And this is how I send data to API



                var jsonData = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync(url, jsonData);
var result = await response.Content.ReadAsStringAsync();









share|improve this question

























  • Convert the string to an array of bytes then you can pass it as a parameter to your SqlCommand

    – Alex K.
    Nov 23 '18 at 13:02











  • What error did you get when excuting the above commands?

    – Steve
    Nov 23 '18 at 13:02











  • @AlexK. - but I just need the one field as a byte not the entire string

    – Doctor Ford
    Nov 23 '18 at 13:32











  • @Steve - see my edit

    – Doctor Ford
    Nov 23 '18 at 13:33
















0















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
XXX.XXX.XX.XXX:XXX/api/user/adduser?firstparam="a"&secparam="b"&thirparam="c"&fourparam="d"&fiveparam="e"&sixparam=123

--SQL DDL
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
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[data1] ON
GO
INSERT [dbo].[data1] ([ID], [badgeIn], [supIn], [phone], [lsc], [email], [gona]) VALUES (1, N'R183', N'TX1384', N'5555555555', N'Test', N'test1234@test.com', 0x477265656E0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
GO
SET IDENTITY_INSERT [dbo].[data1] OFF
GO

--Stored Proc
ALTER PROCEDURE [dbo].[InsertData] @badgeIn varchar(100), @supIn varchar(100), @Phone varchar(100), @lsc varchar(100), @Email varchar(100), @gona binary(64)

AS

INSERT INTO dbo.appinfo (badgeIn, supIn, phone, lsc, email, gona) VALUES (@badgeIn, @supIn, @Phone, @lsc, @Email, @gona)


EDIT

The error shown in my response variable is:




{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.NSUrlSessionHandler+NSUrlSessionDataTaskStreamContent, Headers:
{
Pragma: no-cache
X-Powered-By: ASP.NET
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
Date: Fri, 23 Nov 2018 13:32:43 GMT
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Content-Length: 36
Expires: -1
}}




And this is how I send data to API



                var jsonData = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync(url, jsonData);
var result = await response.Content.ReadAsStringAsync();









share|improve this question

























  • Convert the string to an array of bytes then you can pass it as a parameter to your SqlCommand

    – Alex K.
    Nov 23 '18 at 13:02











  • What error did you get when excuting the above commands?

    – Steve
    Nov 23 '18 at 13:02











  • @AlexK. - but I just need the one field as a byte not the entire string

    – Doctor Ford
    Nov 23 '18 at 13:32











  • @Steve - see my edit

    – Doctor Ford
    Nov 23 '18 at 13:33














0












0








0








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
XXX.XXX.XX.XXX:XXX/api/user/adduser?firstparam="a"&secparam="b"&thirparam="c"&fourparam="d"&fiveparam="e"&sixparam=123

--SQL DDL
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
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[data1] ON
GO
INSERT [dbo].[data1] ([ID], [badgeIn], [supIn], [phone], [lsc], [email], [gona]) VALUES (1, N'R183', N'TX1384', N'5555555555', N'Test', N'test1234@test.com', 0x477265656E0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
GO
SET IDENTITY_INSERT [dbo].[data1] OFF
GO

--Stored Proc
ALTER PROCEDURE [dbo].[InsertData] @badgeIn varchar(100), @supIn varchar(100), @Phone varchar(100), @lsc varchar(100), @Email varchar(100), @gona binary(64)

AS

INSERT INTO dbo.appinfo (badgeIn, supIn, phone, lsc, email, gona) VALUES (@badgeIn, @supIn, @Phone, @lsc, @Email, @gona)


EDIT

The error shown in my response variable is:




{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.NSUrlSessionHandler+NSUrlSessionDataTaskStreamContent, Headers:
{
Pragma: no-cache
X-Powered-By: ASP.NET
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
Date: Fri, 23 Nov 2018 13:32:43 GMT
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Content-Length: 36
Expires: -1
}}




And this is how I send data to API



                var jsonData = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync(url, jsonData);
var result = await response.Content.ReadAsStringAsync();









share|improve this question
















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
XXX.XXX.XX.XXX:XXX/api/user/adduser?firstparam="a"&secparam="b"&thirparam="c"&fourparam="d"&fiveparam="e"&sixparam=123

--SQL DDL
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
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[data1] ON
GO
INSERT [dbo].[data1] ([ID], [badgeIn], [supIn], [phone], [lsc], [email], [gona]) VALUES (1, N'R183', N'TX1384', N'5555555555', N'Test', N'test1234@test.com', 0x477265656E0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
GO
SET IDENTITY_INSERT [dbo].[data1] OFF
GO

--Stored Proc
ALTER PROCEDURE [dbo].[InsertData] @badgeIn varchar(100), @supIn varchar(100), @Phone varchar(100), @lsc varchar(100), @Email varchar(100), @gona binary(64)

AS

INSERT INTO dbo.appinfo (badgeIn, supIn, phone, lsc, email, gona) VALUES (@badgeIn, @supIn, @Phone, @lsc, @Email, @gona)


EDIT

The error shown in my response variable is:




{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.NSUrlSessionHandler+NSUrlSessionDataTaskStreamContent, Headers:
{
Pragma: no-cache
X-Powered-By: ASP.NET
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
Date: Fri, 23 Nov 2018 13:32:43 GMT
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Content-Length: 36
Expires: -1
}}




And this is how I send data to API



                var jsonData = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync(url, jsonData);
var result = await response.Content.ReadAsStringAsync();






c# asp.net sql-server api tsql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 13:39







Doctor Ford

















asked Nov 23 '18 at 12:54









Doctor FordDoctor Ford

597




597













  • Convert the string to an array of bytes then you can pass it as a parameter to your SqlCommand

    – Alex K.
    Nov 23 '18 at 13:02











  • What error did you get when excuting the above commands?

    – Steve
    Nov 23 '18 at 13:02











  • @AlexK. - but I just need the one field as a byte not the entire string

    – Doctor Ford
    Nov 23 '18 at 13:32











  • @Steve - see my edit

    – Doctor Ford
    Nov 23 '18 at 13:33



















  • Convert the string to an array of bytes then you can pass it as a parameter to your SqlCommand

    – Alex K.
    Nov 23 '18 at 13:02











  • What error did you get when excuting the above commands?

    – Steve
    Nov 23 '18 at 13:02











  • @AlexK. - but I just need the one field as a byte not the entire string

    – Doctor Ford
    Nov 23 '18 at 13:32











  • @Steve - see my edit

    – Doctor Ford
    Nov 23 '18 at 13:33

















Convert the string to an array of bytes then you can pass it as a parameter to your SqlCommand

– Alex K.
Nov 23 '18 at 13:02





Convert the string to an array of bytes then you can pass it as a parameter to your SqlCommand

– Alex K.
Nov 23 '18 at 13:02













What error did you get when excuting the above commands?

– Steve
Nov 23 '18 at 13:02





What error did you get when excuting the above commands?

– Steve
Nov 23 '18 at 13:02













@AlexK. - but I just need the one field as a byte not the entire string

– Doctor Ford
Nov 23 '18 at 13:32





@AlexK. - but I just need the one field as a byte not the entire string

– Doctor Ford
Nov 23 '18 at 13:32













@Steve - see my edit

– Doctor Ford
Nov 23 '18 at 13:33





@Steve - see my edit

– Doctor Ford
Nov 23 '18 at 13:33












1 Answer
1






active

oldest

votes


















0














You could convert your string to a byte array and then convert that array to a base64 string which would be your target format to use in your insert operation



    public string convertToBinString(String gona)
{
byte gonaArray = System.Text.Encoding.UTF8.GetBytes(gona);
return Convert.ToBase64String(gonaArray);
}





share|improve this answer
























  • Forgive my ignorance, but once I convert how would I then append it back to send to my API?

    – Doctor Ford
    Nov 23 '18 at 13:38











  • @DoctorFord may be I misunderstood the fact that you are trying to send the data from a javascript environment instead of processing them in a c# context, so, if you are trying to send data from javascript, then you could use the javascript funcion to convert a string to base64 sequence btoa(), once your normal string be enconded to a base64 string then you post it to your API endpoint

    – Wilson Crespo
    Nov 23 '18 at 14:12











  • yes that resolved my issue. Thank you kindly

    – Doctor Ford
    Nov 25 '18 at 1:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447127%2finsert-data-into-binary64-column-from-asp-net-api%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You could convert your string to a byte array and then convert that array to a base64 string which would be your target format to use in your insert operation



    public string convertToBinString(String gona)
{
byte gonaArray = System.Text.Encoding.UTF8.GetBytes(gona);
return Convert.ToBase64String(gonaArray);
}





share|improve this answer
























  • Forgive my ignorance, but once I convert how would I then append it back to send to my API?

    – Doctor Ford
    Nov 23 '18 at 13:38











  • @DoctorFord may be I misunderstood the fact that you are trying to send the data from a javascript environment instead of processing them in a c# context, so, if you are trying to send data from javascript, then you could use the javascript funcion to convert a string to base64 sequence btoa(), once your normal string be enconded to a base64 string then you post it to your API endpoint

    – Wilson Crespo
    Nov 23 '18 at 14:12











  • yes that resolved my issue. Thank you kindly

    – Doctor Ford
    Nov 25 '18 at 1:50
















0














You could convert your string to a byte array and then convert that array to a base64 string which would be your target format to use in your insert operation



    public string convertToBinString(String gona)
{
byte gonaArray = System.Text.Encoding.UTF8.GetBytes(gona);
return Convert.ToBase64String(gonaArray);
}





share|improve this answer
























  • Forgive my ignorance, but once I convert how would I then append it back to send to my API?

    – Doctor Ford
    Nov 23 '18 at 13:38











  • @DoctorFord may be I misunderstood the fact that you are trying to send the data from a javascript environment instead of processing them in a c# context, so, if you are trying to send data from javascript, then you could use the javascript funcion to convert a string to base64 sequence btoa(), once your normal string be enconded to a base64 string then you post it to your API endpoint

    – Wilson Crespo
    Nov 23 '18 at 14:12











  • yes that resolved my issue. Thank you kindly

    – Doctor Ford
    Nov 25 '18 at 1:50














0












0








0







You could convert your string to a byte array and then convert that array to a base64 string which would be your target format to use in your insert operation



    public string convertToBinString(String gona)
{
byte gonaArray = System.Text.Encoding.UTF8.GetBytes(gona);
return Convert.ToBase64String(gonaArray);
}





share|improve this answer













You could convert your string to a byte array and then convert that array to a base64 string which would be your target format to use in your insert operation



    public string convertToBinString(String gona)
{
byte gonaArray = System.Text.Encoding.UTF8.GetBytes(gona);
return Convert.ToBase64String(gonaArray);
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 13:32









Wilson CrespoWilson Crespo

1




1













  • Forgive my ignorance, but once I convert how would I then append it back to send to my API?

    – Doctor Ford
    Nov 23 '18 at 13:38











  • @DoctorFord may be I misunderstood the fact that you are trying to send the data from a javascript environment instead of processing them in a c# context, so, if you are trying to send data from javascript, then you could use the javascript funcion to convert a string to base64 sequence btoa(), once your normal string be enconded to a base64 string then you post it to your API endpoint

    – Wilson Crespo
    Nov 23 '18 at 14:12











  • yes that resolved my issue. Thank you kindly

    – Doctor Ford
    Nov 25 '18 at 1:50



















  • Forgive my ignorance, but once I convert how would I then append it back to send to my API?

    – Doctor Ford
    Nov 23 '18 at 13:38











  • @DoctorFord may be I misunderstood the fact that you are trying to send the data from a javascript environment instead of processing them in a c# context, so, if you are trying to send data from javascript, then you could use the javascript funcion to convert a string to base64 sequence btoa(), once your normal string be enconded to a base64 string then you post it to your API endpoint

    – Wilson Crespo
    Nov 23 '18 at 14:12











  • yes that resolved my issue. Thank you kindly

    – Doctor Ford
    Nov 25 '18 at 1:50

















Forgive my ignorance, but once I convert how would I then append it back to send to my API?

– Doctor Ford
Nov 23 '18 at 13:38





Forgive my ignorance, but once I convert how would I then append it back to send to my API?

– Doctor Ford
Nov 23 '18 at 13:38













@DoctorFord may be I misunderstood the fact that you are trying to send the data from a javascript environment instead of processing them in a c# context, so, if you are trying to send data from javascript, then you could use the javascript funcion to convert a string to base64 sequence btoa(), once your normal string be enconded to a base64 string then you post it to your API endpoint

– Wilson Crespo
Nov 23 '18 at 14:12





@DoctorFord may be I misunderstood the fact that you are trying to send the data from a javascript environment instead of processing them in a c# context, so, if you are trying to send data from javascript, then you could use the javascript funcion to convert a string to base64 sequence btoa(), once your normal string be enconded to a base64 string then you post it to your API endpoint

– Wilson Crespo
Nov 23 '18 at 14:12













yes that resolved my issue. Thank you kindly

– Doctor Ford
Nov 25 '18 at 1:50





yes that resolved my issue. Thank you kindly

– Doctor Ford
Nov 25 '18 at 1:50


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447127%2finsert-data-into-binary64-column-from-asp-net-api%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Sphinx de Gizeh

Fiat S.p.A.