Can someone help me convert this SQL SELECT statement to ASP.NET code (if possible):

SELECT * FROM tblCategory RIGHT JOIN tblInventory ON tblCategory.categoryID = tblInventory.categoryID
WHERE (((tblInventory.type)=[strSearch])) OR (((tblInventory.country)=[strSearch])) OR (((tblInventory.date)=[strSearch])) OR (((tblInventory.eventSeries)=[strSearch])) OR (((tblInventory.grade)=[strSearch])) OR (((tblInventory.comment)=[strSearch]));

I'm trying to use it as a SelectCommand.

Recommended Answers

All 5 Replies

Dim conn1 as new data.sqlclient.sqlconnection(CONNECTIONSTRING)
Dim Select_String as String = WHAT YOU JUST WROTE
Dim Select_Adapter as new data.sqlclient.sqldataadapter(Select_String,conn1)
Dim YourDataSet as New Data.Dataset
conn1.open
Select_Adapter.Fill(YourDataSet)
conn1.close

There are free converters to C# if you need.

Thanks for the reply. What I'm actually trying to do is to get it to bind to a GridView and set strSearch equal to a QueryString @search.

So in my Page_Load, I have:

Dim strSearch As String = Request.QueryString("@search")

Then I have an AccessDataSource defined in my aspx file, and this is what I currently have:

<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/coindata.mdb"
        SelectCommand="SELECT * FROM tblCategory RIGHT JOIN tblInventory ON tblCategory.categoryID = tblInventory.categoryID WHERE (((tblInventory.type)=[strSearch])) OR (((tblInventory.country)=[strSearch])) OR (((tblInventory.date)=[strSearch])) OR (((tblInventory.eventSeries)=[strSearch])) OR (((tblInventory.grade)=[strSearch])) OR (((tblInventory.comment)=[strSearch]));">
    </asp:AccessDataSource>

So if I try to pass a variable onto this page using frmSearch.aspx?@search=Lincoln for example, then I get a "No value given for one or more required parameters" error.

Any help? Sorry I didn't provide more detail earlier.

You are doing it all wrong. How much experience in this do you have?

You are doing it all wrong. How much experience in this do you have?

Not much at all lol.

Use store procedure with parametr @strSearch then pass a strSearch value through SQL parameter.value

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.