Private Sub InsertDataIntoSQL()
Dim query As String = String.Empty
query &= "INSERT INTO QCITT.dbo.DailySales (Row,Location,TransactionDate,CheckbookID,Description,DailyTotal,Account,DistributionReference,Debit,Credit,Type,ShiftType,InGP)"
query &= "VALUES (NEWID(),@Location,@TransactionDate,@CheckbookID,@Description,@DailyTotal,@Account,@DistributionReference,@Debit,@Credit,@Type,@ShiftType,@InGP)"
Dim consString As String
If cbTrustedConnection.Checked = True Then
consString = ("Server=" & tbComputerName.Text & ";Database=" & tbSQLDatabase.Text & ";user=" & tbSQLUser.Text & ";Trusted_Connection=true")
Else
consString = ("Server=" & tbSQLServerName.Text & ";Database=" & tbSQLDatabase.Text & ";user=" & tbSQLUser.Text & ";password=" & tbSQLPassword.Text)
End If
Using conn As New SqlConnection(consString)
Using comm As New SqlCommand()
With comm
.Connection = conn
.CommandType = CommandType.Text
.CommandText = query
'.Parameters.AddWithValue("@Row", NEWID())
.Parameters.AddWithValue("@Location", "Test1")
.Parameters.AddWithValue("@TransactionDate", "01/02/2024")
.Parameters.AddWithValue("@checkbookID", "Test3")
.Parameters.AddWithValue("@Description", "Test4")
.Parameters.AddWithValue("@DailyTotal", "0")
.Parameters.AddWithValue("@Account", "0")
.Parameters.AddWithValue("@DistributionReference", "Test5")
.Parameters.AddWithValue("@Debit", "0")
.Parameters.AddWithValue("@Credit", "0")
.Parameters.AddWithValue("@Type", "0")
.Parameters.AddWithValue("@ShiftType", "0")
.Parameters.AddWithValue("@InGP", "0")
End With
Try
conn.Open()
comm.ExecuteNonQuery()
Catch ex As SqlException
MsgBox(ex.Message, "Error Message")
End Try
End Using
End Using
End Sub