Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

foreach loop through Listview to populate .mdb file

foreach .mdb olddbcommand loop

  • Please log in to reply
1 reply to this topic

#1 emillion


    CC Lurker

  • New Member
  • Pip
  • 7 posts
  • Location:south florida
  • Programming Language:C#
  • Learning:C#

Posted 01 November 2012 - 07:59 PM

I have a listView with subitems that get populated by various user input objects. Once the listView is populated to the users satisfaction I'm trying to get the subitems to populate various columns of a .mdb file.

To complicate matters, some columns are static/preset data while others need to be drawn from the listView. Unfortunatly due to the nature of the project I'm unable to modify the structure of the table.

for example sake, the end result of the populated row in the mdb will look something like this:
staticValue1, staticValue2, (dynamicValue1), (dynamicValue2), staticValue3, (dynamicValue3), staticValue4....etc

I believe I'm on the right track. so far I'm able to simpily able to loop through the listView and display the subitems.

foreach (ListViewItem toSenditems in this.listView1.Items)
// create a new row
for (int i = 0; i < toSenditems.SubItems.Count; i++)
// insert dynamic items from listView (toSenditems.SubItems[i].Text);
//insert non static items in same row

I'm a novice to C# and SQL so any input is welcomed. Please help direct me as to where in the loop I need to put my oleDBcommands and how to structure these queries.
  • 0

#2 BlackRabbit


    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 01 November 2012 - 08:19 PM

You are somewhere near the right track :D

But i think you can see this tutorial useful : working with datatables, datacolumns, dataviews, etc.

I think you should own your DataTable or Dataview, and use that to impact in the database.

as for where do you need to put your ODBC sentences, before the loop goes the open connection, before the finishing of row looping goes the insert, and after the loop the close.
  • 0

Also tagged with one or more of these keywords: foreach, .mdb, olddbcommand, loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download