CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2012
    Posts
    2

    Question Retrieve all records when SelectCommand.Parameters[].Value is null

    hi every body
    I have a SelectCommand and i use code below to set it value
    Code:
    DataAdapter.SelectCommand.Parameters["@code"].Value = str_code;
    and i defin the parameters with code:
    Code:
    DataAdapter.SelectCommand.CommandText = "SELECT * FROM Table  where (code= @code)";
                DataAdapter.SelectCommand.Parameters.Add("@code", SqlDbType.NVarChar, 50, "code");
    now i want when str_code is null SelectCommand retrieve all records in database but i dont want to use condition statments becaus i have many parameters and then i have to write about 100 if-then
    i need a T-SQL for doing it

    thank you all.

  2. #2
    Join Date
    Nov 2011
    Posts
    36

    Re: Retrieve all records when SelectCommand.Parameters[].Value is null

    You can pass the parameter to a stored procedure and check in there if it is null or 0 then do the Select all, and use a reader to get the results?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured