Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
In vb.net how to pass the byte() in stored procedure?
Message
From
06/01/2011 06:04:35
 
 
To
06/01/2011 01:18:43
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01494869
Message ID:
01494914
Views:
81
>
Because i want to do the login page, my table is login(id nvarchar(20), password varbinary(max))
>in first , i have already  result  (encryptByte As Byte()  and  hex ) 
>           
>            Dim encryptByte As Byte() = sqlCmd.ExecuteScalar()
>            Dim hex As String = "0x" + BitConverter.ToString(encryptByte).Replace("-", "")
>
>But question is coming, i have StoredProcedure sp_insertLogin... in part 2,
>@valueVarbinary < must pass the varbinary, and table field "password" also varbinary that is ok 
>But in the first  's result encryptByte(0)> 0 , encryptByte(1)> 0,encryptByte(2)> 0,encryptByte(3)> 123 ....last one is encryptbyte(35)...>197..
>
>           Dim insertLoginCmd As New SqlClient.SqlCommand("sp_insertLogin", cn)
>                    insertLoginCmd.CommandType = CommandType.StoredProcedure
>                    insertLoginCmd.Parameters.Add("@tablename", SqlDbType.NVarChar).Value = "Login"
>                    Dim objinserKeytParameter As SqlParameter = New SqlParameter("@pKey", SqlDbType.NVarChar, 20)
>                    insertLoginCmd.Parameters.Add(objinserKeytParameter)
>                    objinserKeytParameter.Value = txtid.Text
>
>                    Dim objinsertParameter As SqlParameter = New SqlParameter("@valueVarbinary", SqlDbType.varBinary)
>                    insertLoginCmd.Parameters.Add(objinsertParameter)
>                    objinsertParameter.Value = encryptByte          '????????My problem in here, if i pass encryptByte the result only take the 0x0 < i feel encryptByte(0), can't take all byte array , if i pass the hex  < error because string , how can i do ???????????????????????????
>                    insertLoginCmd.ExecuteNonQuery()
>
That code should work (providing you have login table and the SP defined correctly). Simpler example that worked for me:
CREATE PROCEDURE [dbo].[sp_insertLogin]
		@pKey NVARCHAR(20),
		@valueVarBinary VARBINARY(MAX)
AS
BEGIN
	INSERT INTO login (id,password) VALUES (@pKey,@valueVarBinary)
END
GO
then:
   Dim encryptByte As Byte() = getEncryption.ExecuteScalar()  'Loads a byte array

        Dim insertLoginCmd As New SqlClient.SqlCommand("sp_insertLogin", cn)
        insertLoginCmd.CommandType = CommandType.StoredProcedure
        Dim objinserKeytParameter As SqlParameter = New SqlParameter("@pKey", SqlDbType.NVarChar, 20)
        insertLoginCmd.Parameters.Add(objinserKeytParameter)
        objinserKeytParameter.Value = "Fred"

        Dim objinsertParameter As SqlParameter = New SqlParameter("@valueVarbinary", SqlDbType.VarBinary)
        insertLoginCmd.Parameters.Add(objinsertParameter)
        objinsertParameter.Value = encryptByte
        insertLoginCmd.ExecuteNonQuery()
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform