Avatar of Member_2_1242703
Member_2_1242703
 asked on

Tilde in SQL & ASP.NET DataReader

I have a datareader bringing in information and assigning it to a label using the code below. Whenever it runs into a tilde (~) in one of the datasets, it chops it off and everything prior to it. How can I get around this?
Private Sub ReadNext()
        Me.ResetDataReader()
        If CType(Session.Item("reader"), Data.SqlClient.SqlDataReader).Read() Then
            If Not CType(Session.Item("reader"), Data.SqlClient.SqlDataReader)("DESCRIPTION") Is DBNull.Value Then
                Label4.Text = CType(Session.Item("reader"), Data.SqlClient.SqlDataReader)("DESCRIPTION").ToString
            Else
                Label4.Text = ""
            End If
           
            
    Private Sub ResetDataReader()
        Dim myConn As New Data.SqlClient.SqlConnection(myConnString)
        Dim mySelectQuery As String = "SELECT * FROM tblMain"
        myCommand = New Data.SqlClient.SqlCommand(mySelectQuery, myConn)
        myConn.Open()
        myReader = myCommand.ExecuteReader
        Session.Item("reader") = myReader
    End Sub

Open in new window

ASP.NET.NET ProgrammingMicrosoft SQL Server 2005

Avatar of undefined
Last Comment
Todd Gerbert

8/22/2022 - Mon
HainKurt

why are you using session here? try this
Private Sub ReadNext()
  ResetDataReader()
end sub                   
            
Private Sub ResetDataReader()
  Dim myConn As New Data.SqlClient.SqlConnection(myConnString)
  Dim mySelectQuery As String = "SELECT * FROM tblMain"
  myCommand = New Data.SqlClient.SqlCommand(mySelectQuery, myConn)
  myConn.Open()
  myReader = myCommand.ExecuteReader

  if myReader.read() then
    If Not myReader("DESCRIPTION") Is DBNull.Value Then
      Label4.Text = CType(Session.Item("reader"), Data.SqlClient.SqlDataReader)("DESCRIPTION").ToString
    Else
      Label4.Text = ""
    End If
  End if
  MyReaded.close()
  myConn.Close()
End Sub

Open in new window

Member_2_1242703

ASKER
Yeah you're right I should have done it that way but either way that does not solve the problem I was asking about. It returns the exact same value either way. For example...

L/NUT,HEX M6,M6X1.0  ~  M6X1.0
returns
M6X1.0
HainKurt

try this:
Private Sub ReadNext() 
  ResetDataReader() 
end sub                    
             
Private Sub ResetDataReader() 
  Dim myConn As New Data.SqlClient.SqlConnection(myConnString) 
  Dim mySelectQuery As String = "SELECT m.*, replace(DESCRIPTION,'~','?') FROM tblMain m" 
  myCommand = New Data.SqlClient.SqlCommand(mySelectQuery, myConn) 
  myConn.Open() 
  myReader = myCommand.ExecuteReader 
 
  if myReader.read() then 
    If Not myReader("DESCRIPTION") Is DBNull.Value Then 
      Label4.Text = myReader("DESCRIPTION").ToString.replace('?','~') 
    Else 
      Label4.Text = "" 
    End If 
  End if 
  MyReaded.close() 
  myConn.Close() 
End Sub

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Todd Gerbert

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.