Re: Losing characters with sql parameterized insert query

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Girish Bharadwaj (girishb_at_mvps.org)
Date: 09/13/04


Date: Mon, 13 Sep 2004 11:55:17 -0400

A dump question, are you sure that txtTest.Text contains all those special
chars?

-- 
Girish Bharadwaj
http://msmvps.com/gbvb
"anony" <nosp@m.com> wrote in message
news:bMh1d.43696$w_4.6339662@twister.tampabay.rr.com...
> Hello,
>
> I can't figure out why my parameterized query from an ASP.NET page is
> dropping "special" characters such as accented quotes & apostrophes, the
> registered trademark symbol, etc.  These symbols insert without problem
from
> query analyzer, so that suggests it's something within ASP.NET.  I've
tried
> using .NET textbox web controls as well as html textareas.  I have a test
> database set up with 4 fields:  varchar, nvarchar, text, and ntext - they
> all do the same thing.  Regular text inserts fine, but it will simply
remove
> the special characters.  I've searched usenet and the web for info, but to
> no avail.  Someone must have expereinced this issue!  I'm running v1.1
with
> the latest SP.  Thanks for any help!  Here's my code, doing my parameters
in
> different ways:
>
> ------------
>
> Dim conCS As SqlConnection
> Dim cmdSqlCommand As SqlCommand
> Dim strSQL As String
> Dim myParam As New SqlParameter
>
> conCS = New SqlConnection(
> ConfigurationSettings.AppSettings("ConnectionString") )
> conCS.Open()
>
> strSQL = " INSERT INTO TEST VALUES (@TEST_VARCHAR, @TEST_NVARCHAR,
> @TEST_TEXT, @TEST_NTEXT) "
>
> cmdSqlCommand = New SqlCommand( strSQL, conCS )
>
> myParam.ParameterName = "@TEST_NVARCHAR"
> myParam.SqlDbType = SqlDbType.NVarchar
> myParam.Value = txtTest.Text
> cmdSqlCommand.Parameters.Add(myParam)
>
> cmdSqlCommand.Parameters.Add( "@TEST_VARCHAR", txtTest.Text )
> cmdSqlCommand.Parameters.Add( "@TEST_TEXT", txtTest.Text )
> cmdSqlCommand.Parameters.Add( "@TEST_NTEXT", txtTest.Text )
>
> cmdSqlCommand.ExecuteNonQuery()
> conCS.Close()
>
> -------------
>
>


Relevant Pages

  • Datagrid problem - no results to page?
    ... Dim objConnection As SqlConnection ... Dim objCommand As SqlCommand ... Dim strSQL As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Allen Brownes Duplicate Record Code
    ... Dim strSql As String ... Dim rs As DAO.Recordset ... Private Sub Command24_DblClick ... Duplicate the main form record and related records in the ...
    (microsoft.public.access.formscoding)
  • Re: sqlcommand
    ... Hitchhiker's Guide to Visual Studio and SQL Server ... widh command builer then additional parameter to the insert command so I can ... looking for a way to make the changes without needing a second sqlcommand ... Dim cn As New SqlConnection("Data Source=localhost;Integrated ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Was passiert mit den Objecten einer Klasse, nachdem die Klasse per Dispose..
    ... > Dim cmd as new SQLCommand ... Instanz von 'SqlCommand' zeigt. ... > Public Class A ... Erst einmal wird 'Class A' so nicht funktionieren, da sie 'IDisposable' ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Was passiert mit den Objecten einer Klasse, nachdem die Klasse per Dispose..
    ... >> Dim cmd as new SQLCommand ... > Das bringt aber nur etwas, wenn nicht noch eine weitere Referenz auf deine ... > Instanz von 'SqlCommand' zeigt. ...
    (microsoft.public.de.german.entwickler.dotnet.vb)