This article was previously published under Q307514
This article has been archived. It is offered "as is" and will no longer be updated.
This article refers to the following Microsoft .NET Framework Class Library namespaces:
When you use Microsoft OLE DB Provider (MSDAORA) or the OLE DB .NET Data Provider for Oracle, if you use a LIKE statement to search fixed-length character types, Oracle does not find any rows if their padding is different.
If you type a value into a fixed-length field that is shorter than the length of that field, the value is padded with trailing spaces to fill the fixed length. When Oracle matches values for fixed-length fields, it matches the entire length of the string, including any trailing spaces.
NOTE: This behavior is not specific to ADO.NET and also occurs when you use Microsoft ActiveX Data Objects (ADO).
To resolve this problem, always use the percentage ("%") wildcard character when you use LIKE statements to compare values in fixed-length fields in an Oracle database. For example:
Copy and paste the following code in the code window after the "Windows Form Designer generated code" region:
Private Sub btnTest_Click(ByVal sender As System.Object, _ByVal e As System.EventArgs) Handles btnTest.Click Dim sConnectionString As String _ = "Provider=MSDAORA.1;User ID=scott;password=tiger;"_ "Data Source=myOracleServer;Persist Security Info=False" Dim mySelectQuery As String _ = "SELECT * FROM TestTable where c1 LIKE ?" Dim myConnection As New OleDbConnection(sConnectionString) Dim myCommand As New OleDbCommand(mySelectQuery, myConnection) 'To resolve this problem, change the parameter 'in the next line to use "%" wildcard character. myCommand.Parameters.Add("@p1", OleDbType.Char, 3).Value = "a" myConnection.Open() Dim myReader As OleDbDataReader = myCommand.ExecuteReader() Dim RecordCount as Integer Try While myReader.Read() RecordCount = RecordCount + 1 MessageBox.Show(myReader.GetString(0).ToString()) End While If RecordCount = 0 then MessageBox.Show("No data returned") Else MessageBox.Show("Number of records returned: " & RecordCount) End If Catch ex As Exception MessageBox.Show(ex.ToString()) Finally 'Always call Close when done reading. myReader.Close() myConnection.Close() End TryEnd Sub
Save your project.
On the Debug menu, click Start, and run your project.
Click the button. Notice that no data is returned.
Change the parameter to use "%" wildcard character as follows:
Microsoft ADO.NET 2.0, Microsoft ADO.NET 1.0, Microsoft ADO.NET 1.1, Microsoft .NET Framework 1.0, Microsoft .NET Framework 1.1, Microsoft .NET Framework 2.0, Microsoft Visual Basic .NET 2002 Standard Edition, Microsoft Visual Basic .NET 2003 Standard Edition, Microsoft Visual Basic 2005