13 Replies - 369 Views - Last Post: 25 January 2013 - 02:50 PM Rate Topic: -----

#1 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

About SQL Query in VB.Net

Posted 25 January 2013 - 12:34 PM

Hello everybody,
I Want to use the SQL query given below
"SELECT * FROM tblEmployees WHERE (EmpName, EmpCity) = '" & txtNameAndCity.text & "'"

Where txtNameAndCity.text = Vishal, Delhi

Here I get the following error
Syntax error (comma) in query expression '((EmpName, EmpCity) = 'Vishal, Delhi')'.

Actually I have the name and city combined (not Different),
So what should be my SQL Query

Does any one know the answer

Thank You

Is This A Good Question/Topic? 0
  • +

Replies To: About SQL Query in VB.Net

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,057
  • Joined: 02-July 08

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 12:39 PM

Separate the name and city into variables. The preference would be to use parameters also.

"SELECT * FROM tblEmployees WHERE EmpName = @empName And EmpCity = @empCity"
Was This Post Helpful? 0
  • +
  • -

#3 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 12:43 PM

First of all thanks _HAWK_ for replying

I just cant seperate them into two different parts
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,057
  • Joined: 02-July 08

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 12:45 PM

Why not?
Was This Post Helpful? 0
  • +
  • -

#5 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 12:48 PM

Because there is no limit of Comma or Spaces in the NameAndCity Fields
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,466
  • Joined: 12-June 08

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 01:03 PM

Let's put it another way - you cannot have a where statement like that so you need to rework something. What exactly, I am not sure.. I don't know what "Because there is no limit of Comma or Spaces in the NameAndCity Fields" means.

Then of course I have to ask - why are you using text fields for double duty? The name "txtNameAndCity" indicates the text box can be a "name" (what ever that is) and/or a "city". Clearly two different roles and they should be treated as such with two different textboxes.
Was This Post Helpful? 1
  • +
  • -

#7 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 01:24 PM

Owww you misunderstood

The textbox was just an example to make the problem simple

Actually :
There are many textboxes to have detail of the employee while adding a record (Here comma and spaces are allowed).
Now a new database file is created whose name is "name, city.accdb" and the record is saved to the database
now If I want to edit this database then I know the name of the database so from that I have to select the record
Then how can I know the name and city individually.
Was This Post Helpful? 0
  • +
  • -

#8 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 01:39 PM

Woah,
You're creating a NEW database for each Name, city or are you confusing some terminology here?
Was This Post Helpful? 0
  • +
  • -

#9 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 01:45 PM

yes,
Exactly.
Was This Post Helpful? 0
  • +
  • -

#10 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 01:48 PM

May I ask why? Other than what you stated above.

Why not create a single database that has multiple tables and in those tables the information you want to store. I mean, it's only the way a database was intended to work.

Let me pose this question, how would you find information on everybody that lives in Spokaine regardless of their name, you just want a list of people from Spokaine.

How are you going to do that?
Was This Post Helpful? 0
  • +
  • -

#11 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 01:55 PM

Quote

Let me pose this question, how would you find information on everybody that lives in Spokaine regardless of their name, you just want a list of people from Spokaine.

How are you going to do that?


I dont need to search this

I am using different databases for different records as each person will get his own details, I mean it is done for some security purpose

And I got the Answer to my original Question
As there is just one record stored in the table I can use this SQL Query
SQL = "SELECT * FROM tblEmployees WHERE SrNo = 1"

Here SrNo is the AutoIncrement Field
Was This Post Helpful? 0
  • +
  • -

#12 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,057
  • Joined: 02-July 08

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 02:06 PM

I don't think your doing this right. You should be adding records into 1 database. You have several fields in a table, you query the Db table and use the where clause on a field in the table and then you will get only the records that match that field.
Was This Post Helpful? 1
  • +
  • -

#13 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 02:23 PM

Thanks for the advice
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,466
  • Joined: 12-June 08

Re: About SQL Query in VB.Net

Posted 25 January 2013 - 02:50 PM

View PostVishal1419, on 25 January 2013 - 02:55 PM, said:

...
I am using different databases for different records as each person will get his own details, I mean it is done for some security purpose
...

I will go a head and say this _is_ being designed wrong. What are these files - Access or just local DB files?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1