Using VWD 2005 Express and Getting Inconsistant Results with QUERY

Last post 07-07-2008 11:37 AM by Scott Bernard. 2 replies.

Sort Posts:

  • Using VWD 2005 Express and Getting Inconsistant Results with QUERY

    07-02-2008, 4:57 PM

    When adding a Query in a TableAdapter I can use the statement

    SELECT     ServicerNbr, Name, Email  FROM  Servicer  WHERE  (Name LIKE @Name + '%')

    generated from Query Builder and click Execute Query and get the same results (rows) as when I right click on the query in the designer and click Preview Data.  Although when I create another TableAdapter and create the Query  

    SELECT     RequestId, Seq, Part, Description, Qty, Amount  FROM  SrvParts  WHERE     (Part LIKE @Part + '%')

    the results are OK when viewed from Query Builder and click Execute Query.   When the query is right clicked on in the designer under the TableAdapter and I click Preview Data I get no records selected unless I key in an entire part number that matches a record in the database.  No partial (or LIKE) matches are found with Preview Data but are found with Execute Query.

    Any clue why results for same query would differ from Execute to Preview.    Also got several other queries with "LIKE" to work on two separate tables.  The "LIKE" doesn't work on Description field in the SrvParts table either.  

    Thought trailing blanks in data may be problem but this doesn't explain why difference between Preview Data and Execute Query. 

  • Re: Using VWD 2005 Express and Getting Inconsistant Results with QUERY

    07-07-2008, 6:57 AM
    Answer

    Hi,

    If the type of column is char or nchar, there is the issue. Because Visual Studio automatically adds space to the right of the parameter, if it is Nchar.

    If so, you can try to change the column of your datatable definition to Nvarchar type.

    You also can try to modify your "Part" parameter in the DataSet.xsd's code (Right click designer -> View Code).

    For example, the @name column is Nchar type, I change it to nvarchar:

                    <SelectCommand>
                      <DbCommand CommandType="Text" ModifiedByUser="true">
                        <CommandText>SELECT     Id, Name, Value FROM Test  WHERE  (Name LIKE @name + '%')</CommandText>
                        <Parameters>
                          <Parameter AllowDbNull="true" AutogeneratedName="name" ColumnName="Name" DataSourceName="aspnetforum.dbo.Test" DataTypeServer="nvarchar(10)" DbType="String" Direction="Input" ParameterName="@name" Precision="0" ProviderType="NvarChar" Scale="0" Size="10" SourceColumn="Name" SourceColumnNullMapping="false" SourceVersion="Current" />
                        </Parameters>
                      </DbCommand>
                    </SelectCommand>

     

    I hope this helps.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: Using VWD 2005 Express and Getting Inconsistant Results with QUERY

    07-07-2008, 11:37 AM

    I checked the field definitions and field "Name" in the example referenced is defined as varchar(50). All other queries (using LIKE as the operator in the filter) that are currently working were defined as varchar(50). The field "Part" was defined as char(50). Even after changing the definition to varchar(50) the problem was not solved. I re-read your post several times and then it hit me. The code was already generated before I changed my field definition. I deleted the SRVPARTS tableadapter. Re-created it. Then added the query again and it worked correctly. I assume this had the same effect as modifying the code as you recommended.

    Thanks!

    Scott

Page 1 of 1 (3 items)
Microsoft Communities
Page view counter