
inserting records into database
Hi Tom,
I like an Insert query in this situation. Here's an example starting from an
existing connection (bpConnection):
Dim bpCommand As OleDbCommand
Dim columnList As String = "readingDate, readingTime, bpSystolic, " _
& "bpDiastolic"
Dim valueList As String = BuildValueList(BPDate.Text, BPTime.Text, _
BPSystolic.Text, BPDiastolic.Text)
Dim sqlInsert As String = String.Concat("INSERT INTO bpReadings (", _
columnList, ") Values (", valueList, ")")
bpConnection.Open()
bpCommand = New OleDbCommand(sqlInsert, bpConnection)
bpCommand.ExecuteNonQuery()
Private Function BuildValueList(ByVal ParamArray valueArray() As _
String) As String
Dim returnString As String
Dim strVal As String
For Each strVal In valueArray
strVal = String.Concat("'", Replace(strVal, "'", "''"), "'")
If returnString = "" Then
returnString = strVal
Else
returnString = String.Concat(returnString, ",", strVal)
End If
Next
Return returnString
End Function
HTH,
--
Jeff Rhodes
Author of "VBTrain.Net: Creating Computer and Web Based Training with Visual
Basic? .NET"
www.vbtrain.net
Home of the Shape and Graphical Text controls
Quote:
> I have an access 2000 database with one table, in wich I want to insert
> records.
> What is the least memory taking way to do this ?
> Thx in advance,
> -------------
> Tom Deseyn