I have a class Vehicle with one or more instances of vehicle, each with a property registration for example.   How do I iterate through each registration for use in sql queries, select and update? Any help appreciated.  I have the code assuming one instance only using @Reg with Query.Parameter.AddWithValue("@Reg", vehicle.getReg()); 解决方案 Hello RichardDunneBSc,What do you mean "I have the code assuming one instance using ..."? If you want to select all registrations from your table. you just use select statement without adding "where" condition, which will return all records. The following is a simple demo for refer. string connectionString = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename =xxxxx\Test.mdf; Integrated Security = True;"; using (SqlConnection connection =new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand("Select registration from vehicle", connection); try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { MessageBox.Show(reader[0].ToString()); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }Sincerely,Fei Hu 这篇关于sql select中的foreach实例属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-03 11:09