Variable Not Found When Looping Through Grouped Query?
Mar 29, 2010
I'm trying to do the following LINQ grouping, which works in the debugger (the results are populated in the GroupedOrders object. But VS 2008 gives me the following error at design time...
Name 'x' is not declared
Dim GroupedOrders = (From m In thisConsultant.orders _
Group m By Key = m.commCode Into Group _
[code]....
View 3 Replies
ADVERTISEMENT
Dec 16, 2011
I have a list of postcodes in a query (ThisInstructorsPostcodes) and another query that pulls back sales referrals (LastWeeksReferrals)I am using the below syntax to perform the linq equivalent of LEFT OUTER JOIN so I always get a postcode back, even if there were no referrals for it.
dim final = from tip in ThisInstructorsPostcodes _
group join lwr in LastWeeksReferrals on tip.PostcodeID equals lwr.PostcodeID Into lwrgrp = group _
from lwrgrpq in lwrgrp.DefaultIfEmpty _[code].....
The results I am getting are so close to what I need, but I am getting a bunch of InstructorReferrals objects in the lwrgrpq column and what I want to do is simple sum of the all the 'Referrals' integers in those InstructorReferrals objects.I thought this would work:
dim final = from tip in ThisInstructorsPostcodes _
group join lwr in LastWeeksReferrals on tip.PostcodeID equals lwr.PostcodeID Into lwrgrp = group _
from lwrgrpq in lwrgrp.DefaultIfEmpty _
select new with {tip.AreaDistrict, lwrgrpq.Sum(function(x) x.Referrals) }
...but it doesn't - fails with the error: Anonymous type member name can be inferred only from a simple or qualified name with no arguments.I have only used this linq query structure in order to mimic the outer join behaviour of sql, does anyone know how I can fix this so that my grouped items are not anonymous types?
View 1 Replies
Mar 25, 2010
I am getting the error:"Range variable 'sender' hides a variable in an enclosing block or a range variable previously defined in the query expression."for this
Imports System.Data.SqlClient
Imports System.Linq
Public Class Form1
[code]....
I can select any other item from the table without the error. "sender" has the same properties as "receiver" in the SQL table.
View 2 Replies
Jul 5, 2011
I am trying to loop an array in a sql insert statement but i can't get it working. Below is a demo i'm trying to get it running. I think i am having problem with the declaration of variable in sql statement.
Public Class Form1
Dim arrayValue(5) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click[code]......
View 4 Replies
Apr 7, 2012
I am trying to run a query an Access db from VB. The general query which I want to run is
SELECT * FROM Patient WHERE Patient.PatientID = ?
or SELECT * FROM Patient WHERE Patient.PatientLname = ?
I tried using an input box which captured the user input and pass that variable to the query, but that failed. Then I read about writing a function and using that, however, I keep getting an error which says Function not defined, but when stepping through the code, it seems to work. Here is my function: [Code]
View 1 Replies
Feb 8, 2012
I have a class with properties in it . The properties in it are all named the same with the columns names in the database.The reason for that is that i want to loop through all the properties within the class and dynamically create an sql query with the parameters in it . Then dynamically create the parameters and add them into the oraclecommand , everything works well until one of the properties ( QTY ) is set to 0 . When it is set to 0 , during the properties loop ,it will check it as nothing and bypasses the QTY property , with that i am missing one of the columns.class with properties , Notice the property Qty it is Nullable(Of Integer) , it is because when inserting data into the database , sometimes i would want it to be null instead of default 0 .
Public Class HDB
Public Property BONum() As String
Public Property Owner() As String
Public Property Qty() As Nullable(Of Integer)
[code]....
View 6 Replies
Jun 15, 2010
In vb.net 2010 I'm trying to find a variable by it's name and put it's content into another variable of the same name. The code below would work for the .content of a label to copy it into another string but for a variable into another variable I might miss someting?
[Code]...
View 2 Replies
Jun 15, 2010
In vb.net 2010 I'm trying to find a variable by it's name and put it's content into another variable of the same name. The code below would work for the .content of a label to copy it into another string but for a variable into another variable I might miss someting?
View 4 Replies
Mar 6, 2012
In one function I have the variable: dim StrProjectNumber = UCase("23-EXP-16284")
However in another form I want to use that same variable in a SQL query, and when I try it says the variable is not declared. Do I have to make a global variable or is there a way around it? If so, how would I go about declaring a global variable?
View 3 Replies
Mar 11, 2010
I'm trying to get some data from an access database and show them in a CheckedListBox The sql quary includes a variable('sport') and it's values is passed by the user when I run the following code an exception is thrown at the line adStudentList.Fill(dsStudentList, "Register") and it says 'no value given for one or more required parameters'
Dim adStudentList As OleDbDataAdapter
Dim dsStudentList As New DataSet
Dim sport As String
sport = cmbSportList.SelectedItem
[code].....
View 3 Replies
Oct 21, 2009
I am trying to get the value of a Query and save it to a variable, The only way i have been successful is through creating a loop and then saving the value of the location...
Below is the
Dim DBConn As OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData As New DataSet
[Code].....
View 11 Replies
Oct 28, 2009
Right now me filling a combobox by this way.
[Code]...
By this way combobox CmbId is storing above sql query ouput. But now i want to get above query ("Select Name from StudentDetails where Id=10 ") result to store in a variable string. How can i do this ?
View 3 Replies
May 18, 2010
[Code]...
I have remplace the keyarr definition by my SQL query: With the code above, I can print both keyarr in a console. What should I change in the _sqlReader.Read() function in order to get keyarr definition like the first code. I would like that keyarr could be
interpreted by the rest of my code.
View 7 Replies
Nov 17, 2010
I have 2 public variables that I declared in form1 of an application. I am trying to call that variable in form2 and then pass that variable in a sql query. [code]...
View 2 Replies
Sep 23, 2009
I have a simple VB.NET 2008 app that users to edit fields in the database. Simple enough as a first "real" project in .NET, right?For one table, I am currently using a DataGridView so it can be edited straight up. However, instead of offering the user the entire table, I'd like to group the data by the 'CompanyNumber' column and use a navigator to page through. In other words, I'd like the DataGridView to show me all the lines related to one company, then click the "next" arrow to show the next company, etc.
View 2 Replies
Apr 19, 2010
I'm having trouble with a LINQ to SQL query getting the min value using Visual Basic. Here's the SQL:
SELECT RC.AssetID, MIN(RC.RecCode) AS RecCode, JA.EngineerNote from JobAssetRecCode RC
JOIN JobAssets JA ON JA.AssetID = RC.AssetID AND JA.JobID = RC.JobID
WHERE RC.InspState = 2 AND RC.RecCode > 0
[code]....
View 1 Replies
Feb 23, 2012
I'm trying to create a program that displays a calculation based on which radio buttons a user clicks on. I'm not getting any errors during writing or run-time, however only one particular calculation ever gets displayed. I'm not sure why, but it's as if I've gotten the program stuck on the section below. The Calories Label only displays the number 12 regardless of anything else being enabled.
weight = Val(WeightTextBox.Text)
activemale = weight * 15
inactivemale = weight * 13
[Code].....
View 2 Replies
Oct 28, 2010
I want to declare a variable to hold the query result from LINQ to SQL like to the following:
Dim query As IQueryable(Of Student)
If isNoUserName Then
query = From st In db.Students _
Order By st.AssignedId Ascending _
[code]....
Return query
Error : conversions from 'System.Linq.IQueryable(Of )' to 'System.Linq.IQueryable(Of Student)'.
How do I declare variable "query" to hold both data from "Student" and "User" tables?
View 1 Replies
Mar 25, 2009
regarding this error: 'sqlquery' is a variable but is used like a method.Near the bold code is it gives the above error.
string[] sqlQuery = new
string[10];
for (int i = 0; i <= sqlQuery.Length - 1; i++)
{
char[] splitterequal = {
[Code]...
View 7 Replies
Apr 24, 2011
How do I assign the query result to a variable.I am using SQLlite. Below is the code for retrieving password from the User Table. I need to compare the given password and the given password.
Dim i As String
Dim p As String
i = txtUserID.Text
[code].....
View 1 Replies
Nov 4, 2010
I have a public variable that I declared in form1 of an application. I am trying to call that variable in form2 and then pass that variable in a sql query.
If I declare
Public Class Form1
Public payPeriodStartDate, payPeriodEndDate As Date
How then to I declare that variable in form2 and how to I pass it to my sql query
SELECT [Exceptions].Employeenumber,[Exceptions].exceptiondate, [Exceptions].starttime, [exceptions].endtime, [Exceptions].code, datediff(minute, starttime, endtime) as duration INTO ScratchPad2[code].....
View 13 Replies
Apr 19, 2012
I need to pass a string variable into a wql query:
Dim booking As String = System.Configuration.ConfigurationManager.AppSettings("PlayersFile")
Dim query1 As New WqlEventQuery( _
[Code]......
However, I'm uncertain how to make the variable booking parsable by the query.
View 2 Replies
Nov 17, 2010
I have 2 public variables that I declared in form1 of an application. I am trying to call that variable in form2 and then pass that variable in a sql query. [code]...
View 14 Replies
Nov 15, 2010
I have a public variable that I declared in form1 of an application. I am trying to call that variable in form2 and then pass that variable in a sql query. If I declare:
Public Class Form1
Public payPeriodStartDate, payPeriodEndDate As Date
How then to I declare that variable in form2 and how to I pass it to my sql query.
Here is the code I have for form1: [Code]
and when I debug this form, no data will appear. I'm sure that it's something wrong with how I'm either calling the variable in form2 or in the query. Can anyone offer any assistance on this?
View 9 Replies
Oct 5, 2010
Do you just need to format the date? Such as msgbox(New Date(2010, 1, 1).ToString("yyyy-MM"))
Or do you need a hashtable:
[Code]...
View 1 Replies
Jun 11, 2011
I am using VS 2010, SQL 2008 express and doing windows applicaion programming in vb.net.I want to write a select query(or Stored Procedure) such that the conditions mentioned under WHERE clause can be variable .like :Select * from TABLE where F1 = var1 and F2 = var2 and F3 = var3.Now on the basis of some conditons the equations in where clause should beused.Say condition is variable value >6.Now in this case ,if
var1 =7 var2 =3 var3 = 8 then the query shud behave like
:
select * from TABLE where F1 = var1 and F3 = var3
[code].....
View 1 Replies
May 21, 2010
I'm looking to store the result of SQL count function in a variable, i've tried numerous ways but haven't managed to get it to work?
View 3 Replies
Sep 16, 2011
This is probably so simple however my brain has decided it wants a night off. I am trying to write a program that uses SQL queries for various tasks but I need it to allow the user to be able to use which ever name they want for the database name. therefore I need to be able to reference the database as a string variable. For Eg:
[Code]...
View 2 Replies
May 17, 2012
I'm just wondering if it's possibe to get the results from a query and then assign the results to a variable. So I will run a query which will return the names of the tables stored in the database, then I want them to be stored in a variable. So it would be something along the lines of:
Dim strFrom AS String = "FROM "
strQuery = "SELECT * FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'Database1'"
con.Open()
[Code]....
View 7 Replies
Jun 11, 2012
I want to query items from countries that are selected from a treeview (with checkboxes). However the number of countries that is selected by the user is not known beforehand. So how can I make a proper query when the number of OR operators is unknown? For example: SELECT DISTINCT Item FROM Countries WHERE Country LIKE @c1 OR @c2 OR @c3 etc� and then add the parameter values based on the selected countries in the treeview. I looked into parameter arrays but can�t make sense out of it really
View 13 Replies