troubleshooting Question

my sql query returns null when executed, what wrong with the code

Avatar of dipster307
dipster307 asked on
Microsoft SQL Server.NET ProgrammingASP.NET
3 Comments1 Solution396 ViewsLast Modified:
The code below, works fine as in it runs and no error is produced. But it doesnt find any values from the table, something is wrong with me using the LIKE statement for SQL.
if I use
"SELECT * FROM ListTable WHERE ListName = '@name';

it works but with the LIKE it returns no values even if I enter the correct name within txtName field.

Any ideas with what is wrong here?

                string selStr = "SELECT * FROM ListTable WHERE ListName LIKE '@name%'";
                SqlCommand cmd = new SqlCommand(selStr, conn);
                lblResultOutput.Text = cmd.CommandText.ToString();
                SqlParameter name = cmd.Parameters.Add("@name", SqlDbType.NVarChar, 150);
                name.Value = txtName.Text;
                rdr = cmd.ExecuteReader();
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros