Search Results

Search found 3 results on 1 pages for 'scaryjones'.

Page 1/1 | 1 

  • VB.net Debug sqldatareader - immediate window

    - by ScaryJones
    Scenario is this; I've a sqldatareader query that seems to be returning nothing when I try to convert the sqldatareader to a datatable using datatable.load. So I debug into it, I grab the verbose SQL query before it goes into the sqldatareader, just to make sure it's formatted correctly. I copy and paste this into SQL server to run it and see if it returns anything. It does, one row. I go back to visual studio and let the program continue, I create a datatable and try to load the sqldatareader but it just returns an empty reader. I'm baffled as to what's going on. I'll copy a version of the code (not the exact SQL query I'm using but close) here: Dim cn As New SqlConnection cn.ConnectionString = <connection string details here> cn.Open() Dim sqlQuery As String = "select * from Products where productid = 5" Dim cm As New SqlCommand(sqlQuery, cn) Dim dr As SqlDataReader = cm.ExecuteReader() Dim dt as new DataTable dt.load(dr) dt should have contents but it's empty. If I copy that SQL query into sql server and run it I get a row of results. Any ideas what I'm doing wrong? ######### UPDATE ############ I've now noticed that it seems to be returning one less row than I get with each SQL query. So, if I run the SQL myself and get 1 row then the datatable seems to have 0 rows. If the query returns 4 rows, the datatable has 3!! Very strange, any ideas anyone?

    Read the article

  • SQL optional parameters through VB.net

    - by ScaryJones
    I've a document search page with three listboxes that allow multiple selections. They're: Category A Year Category B Only category A is mandatory, the others are optional parameters and might be empty. Each document can belong to multiple options in Category A and multiple options Category B but each document only has one year associated with it. I've kind of got this working through building up a dynamic SQL string but it's messy and I hate using it so I thought I'd ask here if anyone could see an easier way of doing this. An example of the kind of dynamic SQL query i end up with follows: select * from library where libraryID in (select distinct libraryID from categoryAdocs where categoryAdocID in (4)) or year in (2004)

    Read the article

  • SQL query select from table and group on other column...

    - by scaryjones
    I'm phrasing the question title poorly as I'm not sure what to call what I'm trying to do but it really should be simple. I've a link / join table with two ID columns. I want to run a check before saving new rows to the table. The user can save attributes through a webpage but I need to check that the same combination doesn't exist before saving it. With one record it's easy as obviously you just check if that attributeId is already in the table, if it is don't allow them to save it again. However, if the user chooses a combination of that attribute and another one then they should be allowed to save it. Here's an image of what I mean: So if a user now tried to save an attribute with ID of 1 it will stop them, but I need it to also stop them if they tried ID's of 1, 10 so long as both 1 and 10 had the same productAttributeId. I'm confusing this in my explanation but I'm hoping the image will clarify what I need to do. This should be simple so I presume I'm missing something.

    Read the article

1