Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Create a Parameterized Query from a Data Table (VB.NET)

$
0
0

Hello Everyone...

I am making a DBMS for a library. For that I have 3 tables:

  • Books_Main (BookID, Title, AuthorID, PublisherID,  NumOfPages, Language, YearPublished, Version, ISBN, Location)
  • Books_Authors (AuthorID, Name)
  • Books_Publishers (PublisherID, Name, Address)

Now I inserted a table adapter and made a new data table called "BasicBookDetails" using the SQL statement:

SELECT Books_Main.BookID as ID, Title, (SELECT Name FROM Books_Authors where Books_Main.AuthorID  = Books_Authors.AuthorID) as Author, (SELECT Name FROM Books_Publishers where Books_Main.PublisherID = Books_Publishers.PublisherID) as Publisher, Language, ISBN, LocationFROM Books_Main

I successfully achieved it! But now I want to create a parameterized query for the BasicBookDetails data table with @Author as my parameter. When I create a new query in the BasicBookDetails data table and use the code:

SELECT ID, Title, Publisher, Language, ISBN, Location
FROM BasicBookDetails
WHERE Author LIKE @Author + '%'

It returns an error in the select statement saying that BasicBookDetails is an invalid object.

When I use the code:

SELECT Books_Main.BookID as ID, Title, (SELECT Name FROM Books_Authors WHERE Books_Main.AuthorID  = Books_Authors.AuthorID AND Name LIKE @Name + '%') as Author, (SELECT Name FROM Books_Publishers WHERE Books_Main.PublisherID = Books_Publishers.PublisherID) as Publisher, Language, ISBN, Location
FROM Books_Main

It returns a table with all rows of every column and only those rows of the authors column which match the parameter. I have remained unable using the IS NOT NULL function.

Any help would be highly appreciated.

P.S. I want only those rows to be returned with contain a value for the authors column.



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>