?
Solved

Datatable created with the DATASET designer return 0 row

Posted on 2014-10-07
6
Medium Priority
?
143 Views
Last Modified: 2014-10-20
I have a problem with a datatableadapter in a c# form using Visual Studio 2013.

All of my datatableadapter are working perfectly except one.

In the Query Builder when I construct the SQL query and testing the result, the data appear correctly. I am getting rows.
In the same datatableadapter, in the preview window, I am writing both parameters and it return zero row. When executing the code, it return zero row.

This is a query on a view.

SELECT        CustID, OfficeRelationID, OfficeID, PostalBox, Facility, FloorCode, RoomNumber
FROM            viewOffices
WHERE        (CustID = @CustID) AND (Facility = @Facility)

                    // Set the Office Room Number
                    DataSet1TableAdapters.viewOfficesTableAdapter daOffice = new DataSet1TableAdapters.viewOfficesTableAdapter();
                    DataSet1.viewOfficesDataTable dtOffice = daOffice.GetData(profiles[0].CustID, profiles[0].PrimaryFacility);
                    if (dtOffice.Rows.Count > 0)
                    {
                        if (dtOffice[0].RoomNumber.Length > 0) 

Open in new window


I am using the same method with many other tableadapter and they all working perfectly.

viewoffice.JPG
Query Builder
QueyBuilder.JPG
Preview Data
PreviewData.JPG
Thanks for any help
viewoffice.JPG
0
Comment
Question by:SergeGregoire
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 40368351
Almost certainly there's something wrong with the parameters, so I would start with examining their properties and ensuring that they correspond to the datatype in the database, and have correct length.

If that does not help, next I would try two things:

1. right-click on "getdata" in the code, and go to "definition"*; this will open up the actual code generated by the wizard for that. Inspect it closely.
2. run Profiler on sql server, and find out what query was sent by preview and what was sent by the code. Find out the difference.

#2 is somewhat more involved, but it's the most powerful, you will see the difference at once.


*) that's how it works in VB that I use. Maybe in C# it's different.
0
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 40368786
It is really hard to tell what the issue is from your screenshots and code snips.

I can only fashion a guess that perhaps, you need to make sure that the parameters you are passing to your report have the same case level as your sql.

For instance, in your sql, you have @Facility.

My experience tells me that if I pass @facility to my report, it won't work because it is looking for same proper case of F instead of f.

Also, make sure you are pointing to correct database and table.
0
 
LVL 1

Author Comment

by:SergeGregoire
ID: 40387375
Hi,

Sorry, I am very busy.

I used a datareader as a work around, but I will try your ideas with the Dataset next week.
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 1

Author Comment

by:SergeGregoire
ID: 40392233
I ran the profiler and it looks like there is a bug in the dataset.

When I run the query from the Query Builder, I am getting the correct result and the data profiler show the following info:

exec sp_executesql N'SELECT CustID, OfficeRelationID, OfficeID, PostalBox, Facility, FloorCode, RoomNumber FROM viewOffices WHERE (CustID = @CustID) AND (Facility = @Facility)',N'@CustID nvarchar(7),@Facility nvarchar(8)',@CustID=N'0005543',@Facility=N'MONTREAL'

Open in new window


When preview the data from the Table Adapter dataset design view, I am getting no result and noticed that the CustID is missing the last digit as shown in the following result.

exec sp_executesql N'SELECT        CustID, OfficeRelationID, OfficeID, PostalBox, Facility, FloorCode, RoomNumber
FROM            viewOffices
WHERE        (CustID = @CustID) AND (Facility = @Facility)',N'@CustID nvarchar(6),@Facility nvarchar(50)',@CustID=N'000554',@Facility=N'MONTREAL'

Open in new window


I finally use a datareader as shown in the following code:
                    string queryString = "SELECT CustID, OfficeRelationID, OfficeID, PostalBox, Facility, FloorCode, RoomNumber FROM viewOffices WHERE (CustID = '" + strCustID + "') AND (Facility = '" + strFacility + "')";
                    using (var connection = new SqlConnection(connStr))
                    {
                        var command = new SqlCommand(queryString, connection);
                        connection.Open();
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {

Open in new window


I can't explain why the last digit of the parameter is lost, but the datareader way is working fine and I will use this method.

Thanks for the suggestions.
0
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 2000 total points
ID: 40392315
I would check the Parameter of the query in Designer, chances are it has specified maximum length=6, so it gets cut off.
sample
0
 
LVL 1

Author Closing Comment

by:SergeGregoire
ID: 40392774
That was the problem. You are the King.

Thank you very much.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question