By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,882 Members | 928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,882 IT Pros & Developers. It's quick & easy.

Inserting & Fetching Data into a column of TEXT Data type in SQL server 2000 Using ASP.NET

P: n/a
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=192.168.151.109;uid=sa;pwd=sa;Initial
Catalog=www_charm_co_uk_latest"
Dim myConnection As New SqlConnection(szCon)
Dim myCommand As New
SqlCommand("DEMO_For_InsertTEXT_Datatype", 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

Jul 16 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.