cmd = New OleDb.OleDbCommand("INSERT INTO [OrderDetail] ([OrderID],[CinemaID], [SeatID], [MovieName],[MovieTime],[Price]) VALUES (@OrderID,@CinemaID, @SeatID,@MovieName,@MovieTime,@Price)", con)
cmd.Parameters.Add("@OrderID", dbase.OleDbType.Numeric, 15).Value = Label11.Text
cmd.Parameters.Add("@CinemaID", dbase.OleDbType.VarChar, 255).Value = Movie.CinID
cmd.Parameters.Add("@SeatID", dbase.OleDbType.VarChar, 255).Value = ListBox1.Items(0)
cmd.Parameters.Add("@MovieName", dbase.OleDbType.VarChar, 255).Value = Movie.MovieN
cmd.Parameters.Add("@MovieTime", dbase.OleDbType.VarChar, 255).Value = Movie.MovieT
Dim Sql As String
Dim data As dbase.OleDbDataReader
Dim cmdd As dbase.OleDbCommand
Sql = "select * from SeatType where ID = """ & SID & """"
cmdd = New dbase.OleDbCommand(Sql, con)
con.Open()
data = cmdd.ExecuteReader
data.Read()
SPrice = data("Price")
cmd.Parameters.Add("@Price", dbase.OleDbType.VarChar, 255).Value = SPrice
con.Close()
con.Open()
cmd.ExecuteNonQuery()
MsgBox("Saved")
con.Close()
我希望整个事情遍历每个循环,因此listbox1.items(0)
只是根据项目索引继续改变。
有没有办法做到这一点?
答案 0 :(得分:1)
这样做你需要的吗?
For Each seatID in ListBox1.Items.Cast(Of String)()
cmd = New OleDb.OleDbCommand("INSERT INTO [OrderDetail] ([OrderID],[CinemaID], [SeatID], [MovieName],[MovieTime],[Price]) VALUES (@OrderID,@CinemaID, @SeatID,@MovieName,@MovieTime,@Price)", con)
cmd.Parameters.Add("@OrderID", dbase.OleDbType.Numeric, 15).Value = Label11.Text
cmd.Parameters.Add("@CinemaID", dbase.OleDbType.VarChar, 255).Value = Movie.CinID
cmd.Parameters.Add("@SeatID", dbase.OleDbType.VarChar, 255).Value = seatID
cmd.Parameters.Add("@MovieName", dbase.OleDbType.VarChar, 255).Value = Movie.MovieN
cmd.Parameters.Add("@MovieTime", dbase.OleDbType.VarChar, 255).Value = Movie.MovieT
'Remainder of your code
Next