I am having difficulties with the following code. When I run it I get a zero length table but if I copy the sql statement out of the third text box go into access and paste it into the sql view and run it I get the one record I’m looking for. -
Dim CaddTxtFile As String = "C:\WINDOWS\Temp\Acad_Log_Out.txt"
-
Dim CaddFile As String, SqlTxt As String
-
-
Dim dSet As New DataSet
-
Dim dAdapter As OleDb.OleDbDataAdapter
-
-
Dim TxtStream As New System.IO.StreamReader(CaddTxtFile)
-
CaddFile = TxtStream.ReadLine
-
TxtStream.Close()
-
-
CaddFile = CaddFile.Substring(0, 5) & "*"
-
SqlTxt = "SELECT CADD_File_Name, Drawing_Number, Drawing_Title FROM Drawing_Log" & " WHERE CADD_File_Name LIKE '" & CaddFile & "'"
-
-
dbCon.Open()
-
dAdapter = New OleDb.OleDbDataAdapter(SqlTxt, dbCon)
-
dAdapter.Fill(dSet, "Log")
-
-
dbCon.Close()
-
-
TxtCadd.Text = dSet.Tables("log").Rows.Count
-
TxtDwg.Text = CaddFile
-
TxtTitle.Text = SqlTxt
-
Any help would be appreciated.
10 1140 Plater 7,872
Recognized Expert Expert
Well I've never seen an unnamed table query return a table name. Get rid of the , "Log") section and use
dAdapter.Fill(dSet);
Note: You can also fill just a DataTable instead of a DataSet if you only are returning one table.
If I change that then what do I change line 20 to to get the information back out of the dataset. Besides My code works fine if i comment out -
& " WHERE CADD_File_Name LIKE '" & CaddFile & "'"
-
Your ad hoc sql - "SELECT CADD_File_Name, Drawing_Number, Drawing_Title FROM Drawing_Log" & " WHERE CADD_File_Name LIKE '" & CaddFile & "'"
Evaluates to: - SELECT CADD_File_Name, Drawing_Number, Drawing_Title FROM Drawing_Log WHERE CADD_File_Name LIKE 'someFileName'
The problem is your like statement is missing the underscore or wildcard character '%'. I think you want your code to look like this: - "SELECT CADD_File_Name, Drawing_Number, Drawing_Title FROM Drawing_Log" & " WHERE CADD_File_Name LIKE '%" & CaddFile & "%'"
or - "SELECT CADD_File_Name, Drawing_Number, Drawing_Title FROM Drawing_Log" & " WHERE CADD_File_Name LIKE '_" & CaddFile & "%'"
Here is the Sql String that is compiled by the code. -
SELECT CADD_File_Name,Drawing_Number,Drawing_Title
-
FROM Drawing_Log
-
WHERE CADD_File_Name LIKE 'C1130*'
-
I would have prefered 'C1130*' to be "C1130*"
But am unsure how to do this and the sql works in access with the single quote vice the double quote.
What's your database? SQL or Access? What versions?
My database is Access 2003
It looks like you're coding in VB.NET. If you are use two " marks to insert a single " inside of quotes. -
"SELECT CADD_File_Name,Drawing_Number,Drawing_Title
-
FROM Drawing_Log
-
WHERE CADD_File_Name LIKE ""C1130*"" "
-
Also, add a break point at the top line and inspect your data objects while your code is running.
I've been playing with this and I think I've narrowed it down to the wild card character. Here is my Code -
Dim CaddTxtFile As String = "C:\WINDOWS\Temp\Acad_Log_Out.txt"
-
Dim CaddFile As String, SqlTxt As String
-
-
Dim dSet As New DataSet
-
Dim dAdapter As OleDb.OleDbDataAdapter
-
-
Dim TxtStream As New System.IO.StreamReader(CaddTxtFile)
-
CaddFile = TxtStream.ReadLine
-
TxtStream.Close()
-
-
CaddFile = ControlChars.Quote & CaddFile.Substring(0, 5) & "*" & ControlChars.Quote
-
CaddFile = ControlChars.Quote & CaddFile.Substring(0, 5) & "-XX" & ControlChars.Quote
-
SqlTxt = "SELECT CADD_File_Name, Drawing_Number, Drawing_Title FROM Drawing_Log" & " WHERE CADD_File_Name LIKE " & CaddFile
-
-
dbCon.Open()
-
dAdapter = New OleDb.OleDbDataAdapter(SqlTxt, dbCon)
-
dAdapter.Fill(dSet, "Log")
-
dbCon.Close()
-
-
TxtCadd.Text = dSet.Tables("Log").Rows.Count
-
TxtDwg.Text = CaddFile
-
TxtTitle.Text = sqlTxt'dSet.Tables("Log").Rows(0).Item(2)
-
Line 11 returns 0 rows where Line 12 returns 1 row. Since the database I’m using has multiple variations for the last three characters I need to be able to use a wild card. Can anybody explain how to use a wild card in this situation? And before somebody suggest it have already tried -
CaddFile = ControlChars.Quote & CaddFile.Substring(0, 5) & "???" & ControlChars.Quote
-
to no avail.
Plater 7,872
Recognized Expert Expert
Try using the % as the wildcard anyway? The .NET warraper classes might convert it to a *, but use the % for consistency
Thank you Plater that was the answer. Sorry Jerry you gave me the answer earlier and I missed it. I didn't realize the % replaced the *. Thanks everybody for all your help.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: NotGiven |
last post by:
session_start();
if (isset($HTTP_SESSION_VARS))&&($HTTP_SESSION_VARS != '')
echo "hello";
It doesn't throw an error it just doesn't display anything
However, this works:
session_start();...
|
by: Chris Schumacher |
last post by:
I wrote the following program to demonstrate an oddity I found in C++.
#include <iostream>
using namespace std;
int main()
{int *p, *q;
p = q;
q = new int;
|
by: Iver Erling Årva |
last post by:
Can anyone please tell me why this doesn't work?
The sign changes when I hit the button, and I get no error messages, but the
textarea doesn't disappear/reappear.
<html>
<head>
<title>New...
|
by: Brett |
last post by:
This code is supposed to work in Netscape 4+ and IE 4+. It works fine in IE
but in Netscape 7.2, I get a blank page. Any suggestions?
Thanks,
Brett
<html>
<head>
|
by: Brian Henry |
last post by:
I get this error
Server Error in '/' Application.
IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
Description: An unhandled exception occurred during the execution of the...
| |
by: MeNotHome |
last post by:
I am trying to automate web browser navigation and form fill out in
vb.net
Why doesn't this work?
AxWebBrowser1.Document.Forms(0).All("action-download").click()
I also tried...
|
by: Giggle Girl |
last post by:
My pages need to unfold gracefully even if Javascript is disabled, but
I can't get this to work?
Please help, Javascript Gurus!!
<noscript>
document.write('<span class=warning><b>Warning</b>:...
|
by: rynato |
last post by:
I have a function moveDiv(divID).
to test to see if the div has moved far enough:
if (new_left < 400)
{
the_timeout = setTimeout("moveDiv("myDiv");",10);
}
WORKS but this DOESN'T
|
by: Joey |
last post by:
I am working on an asp.net 1.1 web app in C#. I downloaded some sample
code that is supposed to allow for me to persist session state. The
code is as follows:
private void PersistSessionState()...
|
by: yawnmoth |
last post by:
http://www.frostjedi.com/terra/scripts/demo/xml.html
The first alert() shows the XML that the server is returning. The
second alert() shows a particular elements nodeValue and, as you can
see,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |