在Microsoft SQL Server中插入定位特定列的值

时间:2018-01-10 07:04:22

标签: sql sql-server

我想插入定位特定列的值。我使用了以下脚本。

"INSERT INTO tbl_user VALUES(UserID = '" + myUser.ID + "', UserName = '" + myUser.Name + "', Password = '" + myUser.Password + "', UserType = '" + myUser.Type + "')";

但它给了我以下错误。

  

' ='。

附近的语法不正确

可能还有其他方法可以执行此任务。但我想以这种方式做到这一点。我可以吗?

2 个答案:

答案 0 :(得分:0)

始终使用参数化查询来纠正您当前的尝试,如下所示

"INSERT INTO tbl_user (UserID, UserName,  UserName , UserType) 
 VALUES('" + myUser.ID + "','" + myUser.Name + "', '" + myUser.Password + "', '" + myUser.Type + "')";

推荐方法是始终使用参数化查询来防止SQL注入攻击

SqlCommand cmd = new SqlCommand("INSERT INTO tbl_user (UserID, UserName,  UserName , UserType) 
                                 VALUES (@UserID,...)", connections)
cmd.Parameters.AddWithValue("@UserID", myUser.ID)
...

答案 1 :(得分:0)

不,你不能按照自己的方式行事。

是:

@objc func pressedTextAction(_ sender: UITextField) {
    self.textFieldElement = "textField1"

    self.updateScrollY()

    textFieldTag += 1
    textDestTag += 1
    uniY += 60
    //let textY = self.uniY + 20

    self.sampleTextField =  UITextField(frame: CGRect(x: self.xValue, y: uniY, width: 200, height: 30))
    self.sampleTextField.placeholder = "Enter placeholder"
    self.sampleTextField.font = UIFont.systemFont(ofSize: 15)
    self.sampleTextField.borderStyle = UITextBorderStyle.roundedRect
    self.sampleTextField.autocorrectionType = UITextAutocorrectionType.no
    self.sampleTextField.keyboardType = UIKeyboardType.default
    self.sampleTextField.returnKeyType = UIReturnKeyType.done
    self.sampleTextField.clearButtonMode = UITextFieldViewMode.whileEditing;
    self.sampleTextField.contentVerticalAlignment = UIControlContentVerticalAlignment.center
    self.sampleTextField.delegate = self as? UITextFieldDelegate
    self.sampleTextField.tag = self.textFieldTag
    print("\(String(describing: self.sampleTextField.tag))")
    self.view.addSubview(self.getFormView)
    self.getFormView.addSubview(self.sampleTextField)
    let frametext = self.sampleTextField.frame.size.height
    self.textObjects?.append(self.sampleTextField as Any)
    self.yValue = self.yValue + Int(frametext) + 20
    self.xValue = 20
    print("You have text field with tag \(self.sampleTextField.tag)")

    let yOftextDest = uniY
    self.textDest = UIButton(frame: CGRect(x: self.xValue + 220, y: yOftextDest + 5, width: 20, height: 20))
    self.textDest.setImage(#imageLiteral(resourceName: "destroyIcon"), for: .normal)
    self.getFormView.addSubview(textDest)

    self.textDest.addTarget(self, action: #selector(pressedTextDestAction(_:)), for: .touchUpInside)
    self.textDest.tag = self.textDestTag
    print("\(String(describing: self.textDest.tag))")
    self.textDestObjects?.append(self.textDest as Any)
    self.enterPlaceholder()


}



@objc func pressedTextDestAction(_ sender: UIButton) {
    self.updateScrollY()
    self.sampleTextField.viewWithTag(sampleTextField.tag)?.removeFromSuperview()
    self.textDest.viewWithTag(textDest.tag)?.removeFromSuperview()

}

https://www.techonthenet.com/sql_server/insert.php