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 1142 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(d Set);
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
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();
if (isset($HTTP_SESSION_VARS))
|
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 Page 1</title>
</head>
|
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
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
| |
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
AxWebBrowser1.Document.Forms(0).All.item("action-download").click()
"action-download" is the name of a submit button
|
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>: You must enable
javascript for this page to work properly!</span>')
</noscript>
|
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()
{
int MilliSecondsTimeOut = (this.Session.Timeout * 60000) - 30000;
string Script = @"
<script type='text/javascript'>
var Count=0;
|
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, outputs "null". The third alert() shows a particular elements
textContent. Atleast in Firefox. In Internet Explorer it returns
"undefined".
...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |