Dim mycommand As SqlCommand
myconnection = New SqlConnection("server=;uid=admin;pwd=;database=payroll")
myconnection.Open()
mycommand = New SqlCommand("INSERT INTO employee_info([employee_id],
[first_name],[last_name],[middle_name],[email],[telephone],
[gender],[status],[date_birth],[hire_date],[street_add],[city],
[state_province]) values ('" & Employee_idTextBox.Text & "','" &
First_nameTextBox.Text & "','" & Last_nameTextBox.Text & "','" &
Middle_nameTextBox.Text & "','" & EmailTextBox.Text & "','" &
TelephoneTextBox.Text & "','" & GenderTextBox.Text & "','" &
StatusTextBox.Text & "','" & Date_birthDateTimePicker.Value.Date &
"','" & Hire_dateDateTimePicker.Value.Date & "','" &
Street_addTextBox.Text & "','" & CityTextBox.Text & "','" &
State_provinceTextBox.Text & "')", myconnection)
mycommand.ExecuteNonQuery()
myconnection.Close()
答案 0 :(得分:0)
与其他人一样,您应该参数化INSERT
以避免SQL注入漏洞。
以下是按Employee_ID
Dim dbConn as SqlConnection
Dim myCommand As SqlCommand
dbConn = New SqlConnection("server=;uid=admin;pwd=;database=payroll")
dbConn.Open()
myCommand = New SqlCommand("SELECT * FROM employee_info WHERE employee_id = @EmployeeId", dbConn)
myCommand.Parameters.AddWithValue("@ EmployeeId", employeeId)
' employeeId in above line is the variable that contains the actual id you want to retrieve
myDataReader = myCommand.ExecuteReader()
' do stuff with the data in myDataReader here
' ...
' .....
myDataReader.Close()
dbConn.Close()