Data into Listbox or DataGridView?
Data into Listbox or DataGridView?
Data into Listbox or DataGridView?
Data into Listbox or DataGridView?
Data into Listbox or DataGridView?
Data into Listbox or DataGridView? Data into Listbox or DataGridView? Data into Listbox or DataGridView? Data into Listbox or DataGridView? Data into Listbox or DataGridView? Data into Listbox or DataGridView? Data into Listbox or DataGridView? Data into Listbox or DataGridView?
Data into Listbox or DataGridView? Data into Listbox or DataGridView?
Data into Listbox or DataGridView?
Go Back  Xtreme Visual Basic Talk > > > Data into Listbox or DataGridView?


Reply
 
Thread Tools Display Modes
  #1  
Old 09-11-2006, 03:23 AM
LauraL LauraL is offline
Regular
 
Join Date: Jun 2005
Posts: 97
Question Data into Listbox or DataGridView?


Hello guys,

I have moved from VBA to Visual Studio 2005 and it is very "painful"
I have now all my data in access database. I need to do the following:

If I choose a number in combobox (for example 22), then access data from the corresponding column header and three columns besides that column would appear into the listbox (or is it better to use datagridview?).

It was quite easy in vba when loading data from excel sheet, but I haven't found a working sample for Visual Studio yet.

Thank you in advance,
Laura
Reply With Quote
  #2  
Old 09-11-2006, 07:08 AM
George7a's Avatar
George7a George7a is offline
History: Jesus Is Risen
 
Join Date: Mar 2005
Location: Nazareth
Posts: 1,697
Default

__________________
Thabet.Net
Reply With Quote
  #3  
Old 09-11-2006, 08:11 AM
LauraL LauraL is offline
Regular
 
Join Date: Jun 2005
Posts: 97
Default

Thank you George7a, I tried to watch the video, but its kinda difficult to learn from this video.

I would really appreaciate if someone could give me a code snippet. I have seen a code for Visual Basic 6, but in Visual Studio 2005 it has an error in every second line (even after conversion).

Pleeaaase help me,
Laura
Reply With Quote
  #4  
Old 09-11-2006, 08:13 AM
George7a's Avatar
George7a George7a is offline
History: Jesus Is Risen
 
Join Date: Mar 2005
Location: Nazareth
Posts: 1,697
Default

Hey,

From the link above you can download the code that was use in the tutorial

- George
__________________
Thabet.Net
Reply With Quote
  #5  
Old 09-11-2006, 09:12 AM
LauraL LauraL is offline
Regular
 
Join Date: Jun 2005
Posts: 97
Default

Yes, I noticed this also now. But I was'nt able to use it fully.
I need to get the data from access database and so it would appear like in my first post.

Laura
Reply With Quote
  #6  
Old 09-11-2006, 10:04 AM
wayneph's Avatar
waynephData into Listbox or DataGridView? wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Can you post what you have so far?
We'll try to help you figure out what you're doing, but we're not going to do it for you.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #7  
Old 09-11-2006, 11:30 PM
LauraL LauraL is offline
Regular
 
Join Date: Jun 2005
Posts: 97
Default

I have tried to develop something from the following:

Code:
Private Sub Form_Load()
Dim i As Integer
Dim Final As Integer
i = 0

LSTbooklist.Clear
Adodc1.CommandType = adCmdTable
Adodc1.Recordset.MoveLast
Final = Adodc1.Recordset.RecordCount
Adodc1.Recordset.MoveFirst
For i = 1 To Final
    LSTbooklist.AddItem Adodc1.Recordset.Fields("Title")
    Adodc1.Recordset.MoveNext
Next i
End Sub
Code:
Private Sub LSTbooklist_Click()
    Adodc1.CommandType = adCmdText
    Dim Title As String
    Title = LSTbooklist.Text
    Adodc1.RecordSource = "Select * from books where [Title] = " & "'" & Title & "'" & ""
    Adodc1.Refresh
    LBLbooktitle2.Caption = Adodc1.Recordset.Fields("Title")
    LBLauthorname2.Caption = Adodc1.Recordset.Fields("Author")
    LBLgenre2.Caption = Adodc1.Recordset.Fields("Genre")
    LBLseries2.Caption = Adodc1.Recordset.Fields("Series")
End Sub
but it seems to be a visual basic 6 code and I have lots of errors in it.

Laura
Reply With Quote
  #8  
Old 09-12-2006, 08:04 AM
wayneph's Avatar
waynephData into Listbox or DataGridView? wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Quote:
Originally Posted by LauraL
but it seems to be a visual basic 6 code and I have lots of errors in it.
And it's a bad VB6 example at that. ADO is much preferable to using the ADODC controls...

Basically you're going to have a few options on how you want to do this, and it will depend on your application. There are some decent Data Examples available from Microsoft here, but I don't think any of them are specifically what you're looking for. But it should cover all the basics.

The main thing you'll need to determine is if you need real-time data, or if you want your application to store it locally and work from the local copy. If you want/need real time data then you'll need to use an OleDbDataReader each time you want to make a connection to your database. Use the OleDbCommand to say what query you want to run, and then use the ExecuteReader method to get the results.

If you want to store the data in your applicaiton you can store it in a DataTable, and use some DataBinding to navigate through your data. In that case you'll want to use an OleDbDataAdapter and use the Fill method to get the data from the database. Then as users select specific records, you can just go to the DataTable, and not have to make a round trip to your database.

Let us know if you have any more questions... Or need help figuring something out.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #9  
Old 09-13-2006, 12:52 AM
LauraL LauraL is offline
Regular
 
Join Date: Jun 2005
Posts: 97
Default

Hello Wayneph,

I haven't still figured out a working example. It seems like I have searched whole internet already but there are usually vb6 examples or samples with sql database. I should use access database.

If you could just give me a simple example how could I retrieve data from access database to listbox and also delete or insert a row to database. It would be a start and would help me a lot.

(Usually I should use real time data).

Thank you in advance,
Laura
Reply With Quote
  #10  
Old 09-13-2006, 08:17 AM
wayneph's Avatar
waynephData into Listbox or DataGridView? wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Unfortunately I'm not the best one for making this sample. 98% of what I do is web pages and SQL Server, so I don't have anything anywhere close to ready for a sample. Why don't you give it a try, post your code back here and we'll try to help you through it.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #11  
Old 09-13-2006, 04:43 PM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

Hi,
This page Getting Started with Data Access has some good links for examples on data access in VS2005. You'll find links to walkthorughs/examples on getting data into a combobox and a datagridview on this page Displaying Data on Forms in Windows Applications.

Hope this helps!
Reply With Quote
  #12  
Old 09-13-2006, 11:54 PM
LauraL LauraL is offline
Regular
 
Join Date: Jun 2005
Posts: 97
Default

Thank you IUnknown, it seems to be a very good link. I will try to get something out of it.

Laura
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Data into Listbox or DataGridView?
Data into Listbox or DataGridView?
Data into Listbox or DataGridView? Data into Listbox or DataGridView?
Data into Listbox or DataGridView?
Data into Listbox or DataGridView?
Data into Listbox or DataGridView? Data into Listbox or DataGridView? Data into Listbox or DataGridView? Data into Listbox or DataGridView? Data into Listbox or DataGridView? Data into Listbox or DataGridView? Data into Listbox or DataGridView?
Data into Listbox or DataGridView?
Data into Listbox or DataGridView?
 
Data into Listbox or DataGridView?
Data into Listbox or DataGridView?
 
-->