|
-
Feb 12th, 2008, 04:04 PM
#1
Thread Starter
Frenzied Member
problem populating dataset [RESOLVED]
I have the following code:
Code:
Dim NumUploads As Integer
Dim myConnString As String = 'My Conn String
Dim myConnection As New SqlConnection(myConnString)
myConnection.Open()
Dim ds As New DataSet
Dim myAdapter As New SqlDataAdapter("select * from uploads where uploadedby = '" + Membership.GetUser(UserName, True).ProviderUserKey.ToString + "'", myConnection)
myAdapter.Fill(ds)
NumUploads = ds.Tables(0).Rows.Count
myConnection.Close()
Return NumUploads
I know that the connection and the sql query are correct and working, the problem is that when I put a breakpoint at NumUploads = ds.Tables(0).Rows.Count, it returns a 0 every time. Why? I know that the sql query should (and does in sql express manager) return 3 records.
Thanks,
Squirrelly1
Last edited by squirrelly1; Feb 12th, 2008 at 04:30 PM.
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
Feb 12th, 2008, 04:13 PM
#2
Re: problem populating dataset
Are you sure your SQL is correct? Do you know exactly what Membership.GetUser(UserName, True).ProviderUserKey.ToString is returning and that there are records in the database with that criteria?
Set that to a string variable and attach the variable into the SQL line. That way, you can breakpoint it easilly to see what it is returning.
Your code looks solid.
-
Feb 12th, 2008, 04:22 PM
#3
Thread Starter
Frenzied Member
Re: problem populating dataset
Yes, the SQL string is getting populated with the provideruserkey correctly. I copied it directly from the Adapter and ran it in management studio. it worked just fine.
I don't understand. Like you said, the code is solid. I know that it is recognizing the table correctly as referenced ( Table(0) ) because it is showing me that it has 9 columns, just no data.
This is really confusing me. IT SHOULD WORK!
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
Feb 12th, 2008, 04:29 PM
#4
Thread Starter
Frenzied Member
Re: problem populating dataset
Wow, it does work...
Key things to remember:
Breaking on a line stops the code before it has a chance to execute it (strange).
Do not change information in your web.config file (when working in ASP.Net and without testing them), then change your code, and expect favorable results.
Thanks for your time,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
Feb 12th, 2008, 04:30 PM
#5
Re: problem populating dataset
I'd honestly double check your data-source. Maybe try manually calling that WHERE clause by just typing something out rather than having it be inserted.
If you know there is data by user 'blah' then change it to "WHERE uploadedby = 'blah'; " just to see if it's returning anything. That'll narrow it down at least.
Pulling data from the right database? I know I once had like 5 identical databases on a server for testing and spent one afternoon wondering why I wasn't getting data only to find out I had my program set to the wrong database...
Who knows? Maybe the data in the database has hidden characters in it or something weird. I see no reason why that shouldn't work.
Edit: LOL, glad you got it working!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|