如何在sql查询命令中使用方法输入中退出的参数?

how to use the parameters exited in a method input in sql query commands?

这是我的代码:

  public void addUser(int id,string username,string password,int 
   accountcredit)
    {
        SqlConnection sq1 = new SqlConnection("Data Source=xxx;Initial Catalog=xxxxx;User ID=xx;Password=xxxxxxx");
        SqlCommand command = new SqlCommand("", sq1);
        command.CommandText = "insert into userData values(@id,@username,@password,@accountcredit) ";
        command.Parameters.AddWithValue("@id", id);
        command.Parameters.AddWithValue("@username", username);
        command.Parameters.AddWithValue("@password", password);
        command.Parameters.AddWithValue("@accountcredit", accountcredit);

        SqlDataAdapter da1 = new SqlDataAdapter(command.CommandText,sq1);

    }

方法 "addUser()" 应该获取 ID、用户名、密码和帐户信用作为参数,并将它们添加到 table 旨在保存用户记录。我尝试使用上面的代码来做到这一点,但我注意到我不能简单地在 SQL 查询中使用方法 addUser() 参数。我的问题是我应该如何在 SQL 查询中使用该方法的参数。真的 非常感谢你们的帮助。

为了巩固部分评论,需要将多余的行替换掉

SqlDataAdapter da1 = new SqlDataAdapter(command.CommandText,sq1);

command.ExecuteNonQuery();

这应该执行您针对数据库构建的查询。