C# - Web Site - SQL Select Statement

后端 未结 5 2075
深忆病人
深忆病人 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

    Change this line:

    comm.CommandText = "SELECT * FROM Customers WHERE CustomerID == " + txtID.Text;
    

    To this line:

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

    Assuming that your customer id is int on the database.

提交回复
热议问题