Wrox Programmer Forums
|
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2007, 08:19 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The code I presented should still work. The code you are showing is simply creating the database. Once that is accomplished, you should be able to use the code I have shown.

However - I suggest that you simplify things a bit and work on one problem at a time.

Is your database actually being created?
If it is, then make sure you can add data to it.
Once you can do that - it is a very simple matter to use the code I have provided in your application.
Make sure that you import the namespace you need (I failed to show this in the code above). This goes at the top of your file:

Imports System.Data.OleDb

Unless I completely misunderstand your request, the little code sample I have provided will do exactly what you are asking for displaying a list based on what a user enters into a textbox. However, if the user can enter new names into the database, you will need to refresh your datatable each time. Just so you know, it took me about 10 minutes to write that and post it here. It is not bullet proof, but it works as a simple example. I can think of at least 10 other ways to do similar functionality, and there is probably 1000 other ways that others have thought of.

For me, the fastest way to get something done is to do the simplest thing possible: do only one little thing at a time and make it work before going on to the next thing. If your database creation is working, and you can populate it with data, you can move on to the next thing, whatever that is. If those things aren't working - get them working first.

Also, it is best for your code (that is, each method) to do just one little thing as well. For example, your CrNewDB_Click method has about 90 lines of code, and it is doing at least 10 different things. Usually, I try to keep my methods to about 5 or 10 lines of code. One step in donig this is to write a method for anything that represents duplicate or repeated code. You have a lot of repeated code in your example. Another step is to identify "large" things and "small" things, and separate them. For example, making a table is "bigger" than adding a column to the table - in other words: making the table "includes" making the columns. So you can separate making a table into its own method, and then that method can call another method that adds a column... and so on.



Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
 
Old March 27th, 2007, 11:33 PM
Authorized User
 
Join Date: Jan 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the tips.
 
Old March 28th, 2007, 09:16 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So is it working or not?

What does any of this code have to do with displaying a grid based on the user input in a text box?

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
 
Old March 28th, 2007, 09:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there... apart that Woody ask.. what did you are trying to achieve with the following code??

 
Quote:
quote: Dim am, f, l, d, s, p, pa, t As String
Quote:
            am = MSTextBox.Text
            f = FNTextBox.Text
            l = LNTextBox.Text
            d = DOBTextBox.Text
            s = ************.Text
            p = Ph1TextBox.Text
            pa = Ph2TextBox.Text
            t = TAPTextBox.Text
            Me.Table1TableAdapter.Fill(Me.NewAppDBDataSet.Tabl e1)
            Table1BindingSource.AddNew()
            MSTextBox.Text = am
            FNTextBox.Text = f
            LNTextBox.Text = l
            DOBTextBox.Text = d
            ************.Text = s
            Ph1TextBox.Text = p
            Ph2TextBox.Text = pa
            TAPTextBox.Text = t


Also please please please use variable names that mean something.. whoever reads you code will not know what is f... also FNTextBox is not a good name for a textbox, better use txtName (for ex.)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
 
Old March 28th, 2007, 11:21 AM
Authorized User
 
Join Date: Jan 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Only this segment has to do about TextBoxes and DataGridView. I am greatful and welcome your or Gonzalo's critic. Would you be interested for some for fee advice?

Private Sub Find_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Find.Click
    If FNTextBox.Text <> "" Then
        Try
           Me.Table1TableAdapter.FillBy(Me.NewAppDBDataSet.Ta ble1, FNTextBox.Text, LNTextBox.Text)
        Catch ex As System.Exception
           System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
 ..........................
        Dim result As Integer = 0
        result = Table1BindingSource.Count
        If result > 1 Then
            Me.TabControl1.SelectedTab = TabPage2
        End If
End Sub

No, it is not working. I get squiggly line under noteGrid (Name noteGrid is not declared)
 
Old March 28th, 2007, 12:52 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

noteGrid is specific to my example code. You need to use the name of the datagrid you are using.
ALL the names used in my code have to be changed to be specific to your application.

Currently my rate is $125 US per hour for consulting with a minimum of 4 hours. But I am sure you can get this figured out on your own with just a little help from people here.

What my code does is retrieve the DataTable that is used to populate a DataGrid. In my example, the Datagrid is named noteGrid.
As the user types characters into the textbox, only a filtered subset of the names will be displayed in the Datagrid.
This is not a bullet-proof example - there are a lot of ways to break it. I was just trying to give you a little working example of how to do what you are asking.

My suggestion is to make a little app that ONLY does what my little sample does. It just needs a textbox and a datagrid control. You have to point it to a database you already have (via the connection string used by the connection object), and use the names for the database, columns, grid, and textbox (and anything else) that is specific to your test. Once you have that working and understand how it does what it does, then you will probably be able to judge if it fits your need or not. Doing a little test app that only contains the new feature you are trying to implement is a good way to proceed.



Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
 
Old March 28th, 2007, 06:20 PM
Authorized User
 
Join Date: Jan 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. I am sure you are worth every penny of your fee. What I am finding frustrating as a newbie that there are no
comprehensive information about all the mysteries surrounding programming. VB6 is not exactly like VB2005 and so on--
the little elves at MS inventing newer and newer advances but information is lacking or hidden behind veils. Just look at
MSDN Online.....ok,enough of this rant. Peace.


 
Old March 28th, 2007, 07:42 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes. There are a number of changes from VB6 to VB.NET. It is really a whole new approach, and it takes time to learn. This is what the world of computers is all about, and it isn't going to get less complicated - only more so.

But we have all had to wade through the difficult times as beginners - and you will be able to do it too. A very important skill to gain is to do learning "spikes". This is where you make a small sample project to experiment with a very narrow slice of something new you have to learn about. The value here is to keep things focused on only the new thing so there are no complicating factors. Once you have mastered it, you can incorporate it into your ongoing project.

Another technique is to change directions and work on something else whenever you get stumped so you don't waste time looking for an answer. You can put out some posts here and there, or look in a book or two, but spend most of your time on something produtive as you track down the answer in parallel.

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
 
Old March 29th, 2007, 04:26 PM
Authorized User
 
Join Date: Jan 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. Your code - of course - works.

To do:
If only one name found by(Firstname like "FirstnameTextBox.Text + %")than open row's data in the "DataEntryForm" <<< Is this attainable?
 
Old March 29th, 2007, 06:31 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes - you can check for just having a single row in the dataview. To do this you just need some code that checks the count of the DataView, such as this (assuming the dataview is named dv) in your txtName_TextChanged event handler after you have populated the grid:

Code:
If dv.Count = 1 Then
    ... do stuff here ...
End If


Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error getting field names from query vbark Access VBA 1 January 23rd, 2007 09:04 PM
Query statement has nonexistent field names-FIXED buddyz Classic ASP Databases 3 August 30th, 2006 09:46 AM
how to Retrieve Column Names Using SQL Query saravananedu Oracle 2 September 10th, 2005 01:57 AM
Query for Column Names and Datatypes rstelma SQL Server 2000 3 August 23rd, 2005 02:52 PM
Retrieve the table names from union query. udayanbi Access 0 July 20th, 2005 01:38 AM





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