p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8 (http://p2p.wrox.com/forumdisplay.php?f=384)
-   -   Inserting D.B. records programatically ( entering the same value in all records ? ) (http://p2p.wrox.com/showthread.php?t=74898)

liamfitz June 22nd, 2009 03:44 PM

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]
Private
Sub 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.


All times are GMT -4. The time now is 10:21 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.