A plain insert-statement (a good-practise one) looks like this:
INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);
One important thing is completely missing from your code:
Sql-Parameters[
^]. They're good for various reasons: Avoiding so-called Sql-Injection-Attacks, avoiding "strange" Sql-Syntax-Errors and making your Sql-Statements better readable and maintainable. Use them right away and you'll (probably ;)) never have troubles with that.
Sql-Parameters are "something like variables" in your Sql-Statements. And in case of Sql-Server you prefix them with an
@
Example:
INSERT INTO Penerima (IDPenerima, MessageHL7, [Tanggal Penerima]) VALUES (@id, @msg, @tp);
To "deliver" the desired values of these parameters along with your Sql-Insert-Statement to the Sql-Server you have to create instances of SqlParameters and add them to the Parameter-Collection of your SqlCommand-Object (also note I left out the "DateValue(..)" and added ".Value" to your DateTimePicker to avoid the error you experienced):
Dim cmd As New SqlCommand(sqlStatement, connection)
cmd.Parameters.AddWithValue("@id", ID_Penerima)
cmd.Parameters.AddWithValue("@msg", Message_HL7)
cmd.Parameters.AddWithValue("@tp", DateTimePicker1.Value)
Finally, to make it good practise (at least as much as I can think of right now), wrap it all into a
Try-Catch-Finally[
^] (just that we don't need the Catch-Part here) which will ensure that your connection always gets properly closed even if there should an exception be thrown between opening and closing it:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connection As New SqlConnection()
connection.ConnectionString = SqlConnectionString
connection.Open()
Try
Dim sqlStatement As String = "INSERT INTO Penerima (IDPenerima, MessageHL7, [Tanggal Penerima]) VALUES (@id, @msg, @tp);"
Dim cmd As New SqlCommand(sqlStatement, connection)
cmd.Parameters.AddWithValue("@id", txtIdPenerima.Text)
cmd.Parameters.AddWithValue("@msg", txtMessageHl7.Text)
cmd.Parameters.AddWithValue("@tp", DateTimePicker1.Value)
cmd.ExecuteNonQuery()
Finally
connection.Close()
End Try
End Sub
And one tip: Visual Studio 2013 Community Edition is way better than VS2010 (at least if you don't have 2010 Ultimate and especially if you have 2010 Express) and it's FREE! :) Download it here:
https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx[
^]
Edit: If there should be syntax-errors in the code (I'm unexperienced with VB but tried my best) please tell if you can't fix it yourself and I will try to help.