HS Banner
Back
Insert into SQL

Author: Admin 03/28/2021
Language: Visual Basic .NET
Tags:


Description:

Simple way to insert into an SQL server database.

Article:

Simple way to insert into an SQL server database with SQLParameters.

Using con As New SqlConnection("Your SQL Connection String")
     con.Open()

     Dim strSQL1 As String = "INSERT INTO ValueLog (Name, Type, Value, DateStamp)" &
                                          "VALUES (@Name,@Type,@Value, @DateStamp)"
     Using cmSQL As New SqlCommand(strSQL1, con)
         cmSQL.Parameters.Add(New SqlParameter("@Name", SqlDbType.VarChar)).Value = Name
         cmSQL.Parameters.Add(New SqlParameter("@Type", SqlDbType.VarChar)).Value = Type
         cmSQL.Parameters.Add(New SqlParameter("@Value", SqlDbType.Float)).Value = Value
         cmSQL.Parameters.Add(New SqlParameter("@DateStamp", SqlDbType.Date)).Value = Format(Now, "MM/dd/yyyy")
         cmSQL.ExecuteNonQuery()
     End Using

End Using


Back
Comments
Add Comment
There are no comments yet.