C# - Web Site - SQL Select Statement

后端 未结 5 1983
深忆病人
深忆病人 2021-01-24 16:29

I want to use a select statement to find if there is a record that already exists. I\'ve put the code below but it throws an error at the dReader = comm.ExecuteReader(); and i\'

5条回答
  •  别那么骄傲
    2021-01-24 16:55

    The equals operator in SQL is just a single =.

    Also, you really shouldn't be concatenating SQL queries like that, you are just opening yourself up to SQL Injection attack. So change it to be like this:

    comm.CommandText = "SELECT * FROM Customers WHERE CustomerID = @CustomerId";
    comm.Parameters.AddWithValue("@CustomerId", txtID.Text);
    

    See Stop SQL Injection Attacks Before They Stop You on MSDN.

提交回复
热议问题