嗨,我创建了一个私有子,代码必须在其中插入一个 mysql 命令....它确实如此,但最有趣的部分是记录从数据库中消失,它在那里但是我停止调试并重新开始它不存在,甚至不存在在数据库中为什么?
Private Sub gravarAtleta()
Dim sqlStatement = "insert into atl([nome],[morada],[sexo],[datan],[telf],[desporto]) "
sqlStatement &= "VALUES (@nome, @morada, @sexo, @datan, @telf, @desporto)"
Using xConn As New SqlConnection(myConnectionString)
Try
Dim xComm As New SqlCommand(sqlStatement, xConn)
With xComm
.CommandType = CommandType.Text
.Parameters.AddWithValue("@nome", txtNome.Text)
.Parameters.AddWithValue("@morada", txtMorada.Text)
.Parameters.AddWithValue("@sexo", ComboSexo.Text)
.Parameters.AddWithValue("@datan", CType(txtDataN.Text, DateTime).ToString("yyyy-MM-dd"))
.Parameters.AddWithValue("@telf", txtTelemovel.Text)
.Parameters.AddWithValue("@desporto", ComboBox1.Text)
End With
xConn.Open()
xComm.ExecuteNonQuery()
xComm.Dispose()
Label1.Content = "O atleta " + txtNome.Text + " foi registado!!!"
Catch ex As SqlException
MsgBox(ex.Message)
Label1.Content = "Falhou a ligação a base de dados!!!"
End Try
End Using
End Sub