TextContent is a byte array but you are trying to use it as a string.
declare it as a string, and remove the convert code.
Quote:
Hello genious people,
>
I m trying to insert a LARGE text from Multiline Textbox into my
table
of sqlserver2000. I m using vs-2005.
>
>
Please note that I dont want to store blob data From FILE TO TABLE,
like storing IMAGE into DB.
>
>
I hav searched lots of articles on that but didn't get success.
>
>
I hav tried following code from somewhere i found.
But I m getting Error that
>
>
"Failed to convert parameter value from a Byte[] to a String." (This
Error is displayed by smart tag of VS-2005) And then when I press
F5 ,
my IE shows following Error.
>
>
/
************************************************** **************************
*****************
>
*************
Object must implement IConvertible.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
>
>
Exception Details: System.InvalidCastException: Object must implement
IConvertible.
>
>
Source Error:
Line 102: Try
Line 103: myConnection.Open()
Line 104: myCommand.ExecuteNonQuery() <---- Here Line is
highlighted by IE
Line 105: myConnection.Close()
Line 106: Response.Write("New TestText successfully
added!")
>
>
************************************************** **************************
*****************
>
*************/
>
>
Please tell me wht is wrong with my following code. & if any wrong
then pls.
>
>
Also pls tell me how to fetch all that data once at a time. Or
required ro use loop like . But dont know syntax. pls help me its
urgent for me.
>
>
Public Sub StoreTextInDB()
Dim intTextSize As Int64
'''''''Dim TextStream As Stream
>
>
'''''' Gets the Size of the Text
intTextSize = Len(Trim(txtDesc.Text))
Dim TextContent(intTextSize) As Byte
'************************************************* ********
' '''''Reads the Image
TextContent =
System.Text.Encoding.Unicode.GetBytes(Trim(txtDesc .Text))
'' ''TextStream = Request.InputStream
'' ''Dim intStatus As Integer
'' ''intStatus = TextStream.Read(TextContent, 0, intTextSize)
''
''************************************************ *********
'' '' Create Instance of Connection and Command Object
Dim szCon As String
szCon = "Data Source=localhost;uid=t;pwd=t;Initial
Catalog=myDb"
Dim myConnection As New SqlConnection(szCon)
Dim myCommand As New
SqlCommand("myStoredProcedure", myConnection)
>
>
'''' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
>
>
Dim prmStudNo As New SqlParameter("@StudNo", SqlDbType.Int,
4)
prmStudNo.Value = 1
myCommand.Parameters.Add(prmStudNo)
>
>
'''''''' Add Parameters to SPROC
Dim prmTestText As New SqlParameter("@TestText",
SqlDbType.Text, 16)
prmTestText.Value = TextContent
myCommand.Parameters.Add(prmTestText)
>
>
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
Response.Write("New TestText successfully added!")
Catch SQLexc As SqlException
Response.Write("Insert Failed. Error Details are: " &
SQLexc.ToString())
End Try
End Sub
>