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

Discussion in 'ASP .Net' started by Bhavesh, Jul 16, 2007.

  1. Bhavesh

    Bhavesh Guest

    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
    Bhavesh, Jul 16, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    2,644
    Alan Silver
    May 25, 2005
  2. =?Utf-8?B?UCBvZiBEaHVtcA==?=

    Problem (Inserting records into sql server 2000 using asp.net)

    =?Utf-8?B?UCBvZiBEaHVtcA==?=, Aug 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    626
    =?Utf-8?B?UCBvZiBEaHVtcA==?=
    Aug 18, 2005
  3. Replies:
    0
    Views:
    316
  4. Bhavesh
    Replies:
    5
    Views:
    611
    Bhavesh
    Jul 18, 2007
  5. Bhavesh
    Replies:
    1
    Views:
    443
    Bhavesh
    Jul 17, 2007
Loading...

Share This Page