Inserting D.B. records programatically ( entering the same value in all records ? )
When I run the following code, it enters the number 1 in every record in the specified field. It should enter the nos. 1 to 144, as I'm sure you can see. Any suggestioins ? ( I've traced the execution step by step, and the value of x increases in increments of 1 as it should ) Please help.[code]
PrivateSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click
' open the connection.
Dim conn_times24 AsNew OleDb.OleDbConnection(CONNECT_STRING)
conn_times24.Open()
' make a command to insert the data
Dim cmd AsNew OleDb.OleDbCommand("INSERT INTO 24hrTimes (Time_Number) VALUES (?)", conn_times24)
' add the numbers 1 to 144 to Time_Number field
Dim x AsByte
For x = 1 To 144
cmd.Parameters.Add(New OleDb.OleDbParameter("Time_Number", x))
' execute the command.
Try
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
EndTry
Next x
conn_times24.Close()
conn_times24.Dispose()
lblOP.Text = " Done ! "
EndSub
the rest works fine ! just the 'for' loop in question.
|