下面的代码只是一个插入代码,它调用我在sql中创建的存储过程 InsertDataIntoTable 。代码有效,但我想添加的是一个消息框(或标签),以确保已成功插入数据。
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles save_btn.Click
Try
sqlCon = New SqlConnection(strConn)
Using (sqlCon)
Dim sqlComm As New SqlCommand()
sqlComm.Connection = sqlCon
sqlComm.CommandText = "InsertDataIntoTable"
sqlComm.CommandType = CommandType.StoredProcedure
sqlComm.Parameters.AddWithValue("Years", ddl_year.SelectedItem.Text)
sqlComm.Parameters.AddWithValue("StateForest", SFtx.Text)
sqlComm.Parameters.AddWithValue("PrivateForest", PFtx.Text)
sqlComm.Parameters.AddWithValue("TotalForest", totalForesttx.Text)
sqlComm.Parameters.AddWithValue("PercentageSF", PercentageSFtx.Text)
sqlComm.Parameters.AddWithValue("PercentageTotal", PercentageTotal.Text)
sqlCon.Open()
sqlComm.ExecuteNonQuery()
End Using
LoadData()
Catch ex As Exception
End Try
答案 0 :(得分:0)
您可以使用sqlComm.ExecuteNonQuery()
:
Dim RowsAffected as Integer = sqlComm.ExecuteNonQuery()
.ExecuteNonQuery
返回受影响的行数,以便您可以比较该值以确保数据已成功插入。
类似的东西:
If RowsAffected > 0 Then
Msgbox("Record has been successfully inserted")
End If