0

I have a string which is an encrypted binary value

(0x00C11EA094DC7F45AD2B13F42E26ED03010000006018F6DFCEC8BAFC47AC2854C21A5B00FEFA7C3035A9A4EF7AEBB9FDADBF7FA4B2E6392EA0DC4614). 

I need to pass the exact above string to a VarBinary column in SQL Server from .net.

How can I do this?

Regards Rajeesh

1 Answer 1

1

You can use

        var input = "your value string";
        var connectionString = "";

        using(var connection = new SqlConnection(connectionString))
        {
           connection.Open();
           using(var command = new SqlCommand("your query : stored procedure", connection))
           {
             command.CommandType = CommandType.StoredProcedure;

             // your parameter in your stored procedure
             SqlParameter parameter = new SqlParameter("@parameter", SqlDbType.VarBinary); 
             parameter.Direction = ParameterDirection.Input;
             parameter.Value = Encoding.ASCII.GetBytes(input);

             command.Parameters.Add(parameter);
             command.ExecuteNonQuery();
            }
         }
Sign up to request clarification or add additional context in comments.

1 Comment

Encoding.ASCII.GetBytes(input) will give us a new binary string and not the one i have in the input variable.... Are u getting my point?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.