2012-07-05 124 views
0

二進制字段我有一個字符串這是一個加密的二進制值更新SQL服務器

(0x00C11EA094DC7F45AD2B13F42E26ED03010000006018F6DFCEC8BAFC47AC2854C21A5B00FEFA7C3035A9A4EF7AEBB9FDADBF7FA4B2E6392EA0DC4614). 

我需要的確切上面的字符串從.NET傳遞到VarBinary列在SQL Server。

我該怎麼做?

問候 Rajeesh

回答

1

您可以使用

 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(); 
      } 
     } 
+0

Encoding.ASCII.GetBytes(輸入)將給予我們一個新的二進制字符串,而不是一個我在輸入變量是....你明白我的意思了嗎? – user1503526 2012-07-05 11:13:20

+0

我理解,我修改我的代碼 – 2012-07-05 14:00:58