How to give ADO.NET Parameters

前端 未结 4 1467
陌清茗
陌清茗 2020-11-30 13:38

I want to create a SQL command that adds record to DB. I tried the following code but it doesn\'t seem to be working:

SqlCommand comand = new SqlCommand(\"IN         


        
4条回答
  •  死守一世寂寞
    2020-11-30 14:12

    In your case, it looks like you're using .NET. Using parameters is as easy as:

    C#

     string sql = "SELECT empSalary from employee where salary = @salary";
     SqlConnection connection = new SqlConnection(/* connection info */);
     SqlCommand command = new SqlCommand(sql, connection);
    
     command.Parameters.AddWithValue("salary", txtSalary.Text);
    

提交回复
热议问题