|
-
Sep 4th, 2014, 10:49 AM
#1
Thread Starter
New Member
After updating the program from XP to Win7 the DataReader doesn't show rows.
Ok I am very new to VB. I have a VB program which was coded originaly in XP. After doing an update on it to be workable on Win7, I faced with some issues. The major issue that I couldn't fix was the DataReader problem. The cmdLink connects to database and Selects the info that I asked but when I'm asking to read in drLink, I get rows=false. It the exact same code. The XP code works fine but the updated one doesn't. Here is my code.
Code:
Private Sub LaunchSpecView(ByVal columns As String)
Dim cn As New OleDb.OleDbConnection(connString)
cn.Open()
Dim CommandLine As String = ""
'set dataReader and Command
Dim cmdLink As New OleDb.OleDbCommand("Select Distinct a.* from ReplaceableAssemblies a, Files b, RefFileTable c Where a.[Ref Des] = '" & Me.RefDes & "' AND c.RepAssemRec = a.RecNo AND b.RecNo = c.FileRec AND b.FileName = '" & My.Forms.MainForm.lblFileName.Text + "'", MainForm.cn)
Dim drLink As OleDb.OleDbDataReader = cmdLink.ExecuteReader Here is my problem
'check that file exists (I will see error message)
If Not System.IO.File.Exists(Directory.GetParent(Directory.GetParent(Application.StartupPath).ToString()).ToString() & "\bin\specview.exe") Then
MessageBox.Show("Check that path is correct. " & vbCrLf & _
"Check that GlobalHawk.exe is as follows ....'IETM\Applications\p2p\GlobalHawk.exe'" & _
vbCrLf & _
"And/Or make sure that specview.exe is in .....IETM\bin\specview.exe", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
drLink.Close()
cn.Close()
Exit Sub
End If
'loop through and grab file
Do While drLink.Read
If Not drLink(columns).ToString().ToLower().Equals("n/a") Then CommandLine += "," & drLink(columns)
Loop
'close connection
drLink.Close()
cn.Close()
If CommandLine.Length > 0 Then
Process.Start(Directory.GetParent(Directory.GetParent(Application.StartupPath).ToString()).ToString() & "\bin\specview.exe", " -loaddm " & CommandLine.Substring(1))
MessageBox.Show(CommandLine.Substring(1))
Me.Close()
End If
End Sub
Last edited by dday9; Sep 4th, 2014 at 04:30 PM.
Reason: Added code tags
-
Sep 4th, 2014, 08:52 PM
#2
Re: After updating the program from XP to Win7 the DataReader doesn't show rows.
I don't see any `rows` anywhere to be false. Do you actually mean the HasRows property of the data reader? If so then that's what you should say. Please always use the correct names for things to avoid confusion.
If that's the case then that means that your query has an empty result set, plain and simple. The very first thing you should be doing is fixing this:
Code:
Dim cmdLink As New OleDb.OleDbCommand("Select Distinct a.* from ReplaceableAssemblies a, Files b, RefFileTable c Where a.[Ref Des] = '" & Me.RefDes & "' AND c.RepAssemRec = a.RecNo AND b.RecNo = c.FileRec AND b.FileName = '" & My.Forms.MainForm.lblFileName.Text + "'", MainForm.cn)
That's bad code for a number of reasons. Most obviously, using string concatenation to insert values into SQL code is almost always a bad idea. You should be using parameters to insert those values. If you don;t know how to do that then follow the Blog link in my signature below and read my post on Parameters In ADO.NET.
There's another apparent issue with the code that I suspect is actually the cause of your problem though. In the lines immediately preceding that one you do this:
Code:
Dim cn As New OleDb.OleDbConnection(connString)
cn.Open()
You create a connection object and assign it to the `cn` variable, presumably with the intention of using that connection for your data reader. You don;t use that connection though. You actually use MainForm.cn; same name but a different variable. I suspect that you actually aren't connecting to the database that you think you are.
If that is the case then that is a good lesson to learn, i.e. just because you're using the same code, don't expect the same output if you don't use the same input. If you actually are connecting to the right database, albeit via the wrong connection, then you've still got some investigation to do.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|