Trying to display 2 tables - vbscript

I tried to display 2 tables using this code but it only display the table two, I am really not sure why does it not display table two here is my piece of code.
sub ExecQry
parent.frames(1).DataForm.Query.value = "SELECT * FROM Table1 WHERE Something = " &some.value
parent.frames(1).DataForm.Query.value = "SELECT * FROM Table2 WHERE something = " &some.value
parent.frames(1).DataForm.submit
end sub

becouse you override the table one try useing this
sub ExecQry
parent.frames(1).DataForm.Query.value = "SELECT * FROM Table1,Table2 WHERE
Something = " &some.value
parent.frames(1).DataForm.submit
end sub
I used Joins to work arround on it

Related

Data does not display

I've got minor trouble. My data does not display.
My web page script is as follows:
sqlWFlexi = "Select StaffDepart,StaffName From Employee Where StaffNo = '"&myStaffNo &"'"
set rsWFlexi = ConnISAS.execute(sqlWFlexi)
if not rsWFlexi.eof then
myWFlexi = rsWFlexi("StaffName")
end if
sql="Select StaffDepart, StaffName from Employee where StaffNo = '" & myWFlexi & "'"
set rs1 = ConnISAS.execute(sql)
if not rs1.eof then
myDept = rs1("StaffDepart")
myNameStaff= rs1("StaffName")
if rs1("WFlexi") = "-" then
myFlexi = "0"
else
myFlexi = "1"
end if
end if
This is supposed to display StaffName and StaffDepart. Can you tell me what exactly is missing in my script?
You have two sql statement, if
myWFlexi = rsWFlexi("StaffName")get value from
sqlWFlexi = "Select StaffDepart,StaffName From Employee Where StaffNo = '"&myStaffNo &"'"
let just say John Smith
and second statement sql="Select StaffDepart, StaffName from Employee where StaffNo = '" & myWFlexi & "'" get value from
myWFlexi = rsWFlexi("StaffName") that mean you want get the data StaffName and StaffDepart from employee based on the value myWFlexi.
The way you declare it is not right way ,that why it do not display data even you already declare response.write
You have not selected WFlexi in the second sql statement.
Also if you have to print anything then you should either use
<%
response.write myDept
%
>
and if you don't want to use response.write then you have to use asp<%=myDept%> tags in html.

How to use multiple inner joins for visual basic 6

I am looking for a way to use 2 inner joins so I can link 3 databases together.
I currently use this :
rs.Open "select * from School inner join Name on School.ID = Name.ID", db, 3, 3
I need to add the database called Opdracht. After the DB are linked I want to link all the IDs together. Like in the code above but then 3 IDs.
I hope you can help me with this.
The specific syntax will depend on the database / driver you are using but you simply add another JOIN statement. I prefer building a string and assigning the string as it makes the code easier to read.
...
Dim strSQL as String
strSQL = "SELECT * FROM (School " & _
"INNER JOIN Name ON School.ID = Name.ID) " & _
"INNER JOIN Opdracht ON Opdracht.ID = Name.ID"
rs.Open strSQL, db, 3, 3
...

LINQ to SQL, Visual Basic - Listbox Receives the Query NOT the Result

Overview
This is a homework assignment using LINQ to SQL in a Visual Basic application. It is correct in most ways except that I have a partially broken result. Rather than adding the result of my second query to my listbox, my code adds a weird representation of the query itself. Below is a description of the DB, followed by my output (intended and actual), and finally my code. Please point me toward the broken concept so I can figure out what I am missing. Thanks much.
DB info
I am using two tables, called Members and Payments, from one DB. Members has a primary key called ID and also has the fields first_name and last_name. Payments has a foreign key called Members_Id, which is associated to the Member's primary key; Payments also has the payment values under the column Payments.
Output should be like this
Member name = John Smith
$48.00, 10/20/2005
$44.00, 3/11/2006
But is this instead
Member name = SELECT ([t0].[First_Name] + #p1) + [t0].[Last_Name]
AS [value]FROM[dbo].[Members] AS [t0].[ID] = #p0
$48.00, 10/20/2005
$44.00, 3/11/2006
My VB Code
Public Class FormPaymentsGroup
Private db As New KarateClassesDataContext
Private Sub FormPaymentsGroup_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.PaymentsTableAdapter.Fill(Me.KarateDataSet.Payments)
'Group payments by Member_ID (FKey) in the Payments table. (Working fine)
Dim IdQuery = From aMember In db.Payments
Group aMember By aMember.Member_Id
Into MemberPayments = Group
For Each memberID In IdQuery
' Use the passed member_Id to target the row in the Members table and return the first_name & last_name.
' PROBLEM: This only seems to be returning the query itself; not the result.
Dim currMemberID = memberID.Member_Id
Dim nameQuery = From aName In db.Members
Where aName.ID = currMemberID
Select aName.First_Name + " " + aName.Last_Name
Dim currName = nameQuery.ToString ' Load the query result into a portable variable.
LbxMemberPayments.Items.Add("Member name = " & currName) ' PROBLEM: This is where the name SHOULD BE posted to the listbox.
' This is bound to the Members table but directs it based on the above IdQuery.
For Each enteredPayment In memberID.MemberPayments
LbxMemberPayments.Items.Add(vbTab & FormatCurrency(enteredPayment.Amount) & ", " & enteredPayment.Payment_Date)
Next
LbxMemberPayments.Items.Add(vbCr) ' Carriage return formatting
Next
End Sub
End Class
change
Dim currName = nameQuery.ToString
to
Dim currName = nameQuery.FirstOrDefault

How does using (RecordSet).EOF on If statements work?

I have these lines of code, from vb6 trying to migrate them to vb.net.
What´s the logic behind them?
RegFileHf.CommandText = "Select dayspassed from Config"
Set UltHf = RegFileHf.Execute
If Not UltHf.EOF Then
someDate = Date - UltHf.Fields("dayspassed")
Else
someDate = Date - 180
End If
Does the If statement executes multiple time until end of file?
Does the else part comes in only when there´s no rows on my SQL query?
(Can you guys recommend good books to learn VB.NET so I can stop making newbie questions?)
Thanks in advance.
EOF condition mean that you get in the end of data .. that mean no row return
So, if there's (a) rows it will fire -> someDate = Date - UltHf.Fields("dayspassed")
If there's no row it fire -> someDate = Date - 180
Something like that ..
In VB.NET
Dim query = "Select dayspassed from Config"
Dim dc = New OleDbCommand(query, connection)
Dim rows As OleDb.OleDbDataReader
rows = dc.ExecuteReader
If rows.HasRows Then
'...... someDate = Date - rows.item("dayspassed")
else
'...... someDate = Date - 180
End If
Book --> try Google to find

Linq Compiled Queries and int[] as parameter

I'm using the following LINQ to SQL compiled query.
private static Func<MyDataContext, int[], int> MainSearchQuery =
CompiledQuery.Compile((MyDataContext db, int[] online ) =>
(from u in db.Users where online.Contains(u.username)
select u));
I know it is not possible to use sequence input paramter for a compiled query and im getting “Parameters cannot be sequences” error when running it.
On another post here related , I saw that there is some solution but I couldn't understand it.
Does anyone know to use complied query with array as input paramter?
Please post example if you do.
Like the post that you referenced, it's not really possible out of the box. The post also references creating your own query provider, but it's a bit of overhead and complexity that you probably don't need.
You have a few options here:
Don't use a compiled query. Rather, have a method which will create a where clause from each item in the array resulting in something like this (psuedo-code):
where
online[0] == u.username ||
online[1] == u.username ||
...
online[n] == u.username
Note that you would have to use expression here to create each OR clause.
If you are using SQL Server 2008, create a scalar valued function which will take a table-valued parameter and a value to compare againt. It will return a bit (to indicate if the item is in the values in the table). Then expose that function through LINQ-to-SQL on your data context. From there, you should be able to create a CompiledQuery for that. Note that in this case, you should take an IEnumerable<string> (assuming username is of type string) instead of an array, just because you might have more than one way of representing a sequence of strings, and to SQL server for this operation, it won't matter what the order is.
One solution that I have found myself doing (for MS SQL 2005/2008). And I'm not sure if it is appropriate in all scenarios is to just write dynamic sql and execute it against the datacontext using the ExecuteQuery method.
For example, if I have an unbounded list that I am trying to pass to a query to do a contains...
' Mock a list of values
Dim ids as New List(of Integer)
ids.Add(1)
ids.Add(2)
' ....
ids.Add(1234)
Dim indivs = (From c In context.Individuals _
Where ids.Contains(c.Id) _
Select c).ToList
I would modify this query to create a SQL string to execute against the database directly like so...
Dim str As New Text.StringBuilder("")
Dim declareStmt as string = "declare #ids table (indivId int) " & vbcrlf)
For i As Integer = 0 To ids.Count - 1
str.Append("select " & ids(i).ToString() & " & vbcrlf)
If i < ids.Count Then
str.Append("union " & vbcrlf)
End If
Next
Dim selStatement As String = "select * From " & context.Mapping.GetTable(GetType(Individuals)).TableName & _
" indiv " & vbcrlf & _
" inner join #ids ids on indiv.id = ids.id"
Dim query = declareStmt & str.ToString & selStatement
Dim result = context.ExecuteQuery(of Individual)(query).ToList
So barring any syntax errors or bugs that I coded (the above is more or less psuedo code and not tested), the above will generate a table variable in SQL and execute an inner join against the desired table (Individuals in this example) and avoid the use of a "IN" statement.
Hope that helps someone out!

Resources