Answered variable from database

thirteentwenty

Well-known member
Joined
Oct 9, 2008
Messages
80
Location
Honolulu
Programming Experience
Beginner
OK, I've officially lost it...

I'm trying to get a database entry (access) and compare it with a value in a textbox... but i cant seem to get the database entry out... I mean I can, but I cant seem to get to be variable...

This is what I've got...

VB.NET:
    Public Function Test()

        com = New OleDb.OleDbCommand("SELECT * FROM Prefs", con)
        da = New OleDb.OleDbDataAdapter
        da.SelectCommand = com
        dt = New DataTable
        da.Fill(dt)

        frm_main.txt_ID.DataBindings.Add("Text", dt, "LastNo")

        da.Dispose()
        da = Nothing
        com.Dispose()
        com = Nothing
        frm_main.txt_ID.DataBindings.Clear()

        Return ""
    End Function

What I need to do is find out if frm_main.txt_ID is the same as LastNo, if it is, move on to do something else, and if not do something else...

My first thought is to get LastNo and say something like

VB.NET:
If LastNo = frm_main.txt_ID.Text Then
'do something
Else
'do something else
End If

Thanks for the assist...

and on another completely different note, is it proper to give a rep-point or something for the aide? and how does one mark the thread as "Answered"?
 
Last edited:
Take a read of the DW2 link in my signature, section "Creating a Simple Data App"


Once you know that and you understand the mdern easy way to do data access, your code will be:

VB.NET:
If txtID.Text = myTableAdapter.GetSomeCertainValue() Then
 'do stuff


Other critiques of your code:

1) don't mix naming conventions for variables. either_name_them_like_this, orNameThemLikeThis
2) adding a databinding then clearing it nanoseconds later is a nonop


Other questions:

Rep anyone you like for whatever. The forum will make sure you don't rep someone too much

You edit your original post and change the title e.g. Find: "Question:" Replace: "Answered"
There is no one-click button, and if your post gets too old, you cannot edit it any more rendering the above advice useless. Because the Question/Resolved system here is lame (Neal's working on it but doesnt want to install hacks that make it usable so is basically waiting for an official fix) I dont bother with it, and I doubt anyone will care if you dont mark your threads as resolved :)
 
cjard

Thanks for the epic advice on this thread and the other. I'm not sure where my head was yesterday but the example you gave is what I ended up doing... I just couldn't think of it at the time and was starting to talk to myself and decided that I needed to put it out there... I actually had forgotten that I had made that post because the answer did come to me after I put the project down for a bit and worked on something else.
 

Latest posts

Back
Top