Access data from a table in Access 2000 Database programmicly

Last post 06-25-2009 1:55 PM by cgould01. 9 replies.

Sort Posts:

  • Access data from a table in Access 2000 Database programmicly

    06-23-2009, 11:20 AM
    • Member
      4 point Member
    • cgould01
    • Member since 05-06-2009, 3:38 PM
    • Posts 19

    I need some help... I am trying to access a table from Access 2000 Database.  The table has 3 columns: UserName, Password, Division

    I need to look through the usernames until I find a match (compairing to a textbox), then check the Password, after which I will then need to store the Division to a Public Variable to set what the user can 'see'.  

    I have a Dataset to the Access 2000 database already in use on another form.  The dataset includes the table called 'sa' which is the table that I am trying to access.

  • Re: Access data from a table in Access 2000 Database programmicly

    06-23-2009, 1:36 PM
    I am assuming your dataset is called myDataSet. You can use the FilterExpression parameter of the Select method that is available for the Tables object as follows:

      

    DataRow[] myDataRows = myDataSet.Tables["sa"].Select("UserName='" + textboxUserName.Text + "' AND Password='" + textboxPassword.Text + "'");
    
    if(myDataRows.Length > 0)
    {
         myVar = myDataRows[0]["Division"].ToString();
    }

     

    Change the name of myDataSet, textboxUserName, textboxPassword, and myVar accordingly and you are all set.

  • Re: Access data from a table in Access 2000 Database programmicly

    06-23-2009, 7:59 PM
    • Member
      4 point Member
    • cgould01
    • Member since 05-06-2009, 3:38 PM
    • Posts 19

    I'm a little confused on something.  I am working in VB and looking at what you have done, I have done this:

    Dim MyDatarows As System.Data.DataRow
            MyDatarows = BatchAideDataSet.Tables("sa").Select("Username='" + UsernameTextBox.Text + "'")

     

    I get the following error on line 2:

    Error 1 Value of type '1-dimensional array of System.Data.DataRow' cannot be converted to 'System.Data.DataRow'. C:\Documents and Settings\cgould\My Documents\Visual Studio 2008\Projects\BatchAide_v2\BatchAide_v2\LoginForm1.vb 20 22 BatchAide_v2

    I don't understand why it can't do it.  Any suggestions? 

  • Re: Access data from a table in Access 2000 Database programmicly

    06-23-2009, 11:21 PM

    Dim MyDatarows() As System.Data.DataRow = BatchAideDataSet.Tables("sa").Select("Username='" + UsernameTextBox.Text + "'")

    ought to do the trick.

  • Re: Access data from a table in Access 2000 Database programmicly

    06-24-2009, 7:23 AM
    Answer
    • Member
      4 point Member
    • cgould01
    • Member since 05-06-2009, 3:38 PM
    • Posts 19

    csgeyer@hotmail.com:

     

     

    1. Dim MyDatarows() As System.Data.DataRow = BatchAideDataSet.Tables("sa").Select("Username='" + UsernameTextBox.Text + "'")  


     

    ought to do the trick.

     

    Hate to keep bothering u on this but, in the above example you gave.  I have a problem with the MyDatarows.Length always being zero (not getting a match from the table I suppose).  I know that there is data in the table and I have checked to make sure there is data in the dataset.  Any ideas?

     

  • Re: Access data from a table in Access 2000 Database programmicly

    06-24-2009, 11:42 AM
    Answer

    Most likely whatever value you are pulling from the TextBox is not in the table.


    Also, I just noticed something. The Select statement should have & signs, not + signs. VB uses "&" to concatenate strings. Changing this should fix the problem. Otherwise, try this. Replace smith in the line below with a username you know is in the table.

    Dim MyDatarows() As System.Data.DataRow = BatchAideDataSet.Tables("sa").Select("Username='smith'"


    (You can find a username by setting a breakpoint (F9) on this line, highlighting BatchAideDataSet.Tables("sa"), right-clicking and choosing Quick Watch. Then drill down into the table's rows and items until you locate a username - this will be good practice for understanding the object model and examining your code more thoroughly. Or you can take the easy path and look up a username from the database).


    You should not have a length of zero after replacing smith in the line above.

  • Re: Access data from a table in Access 2000 Database programmicly

    06-24-2009, 3:08 PM
    • Star
      8,280 point Star
    • hans_v
    • Member since 01-29-2007, 9:03 PM
    • Posts 1,423

    cgould01:
    I need to look through the usernames until I find a match (compairing to a textbox), then check the Password, after which I will then need to store the Division to a Public Variable to set what the user can 'see'.
     

    It looks to me that you're trying to reinvented a wheel that Microsoft already invented...

    Using the Microsoft Access Providers to Replace the Built-In SQL Server Providers

  • Re: Access data from a table in Access 2000 Database programmicly

    06-25-2009, 9:33 AM
    • Member
      4 point Member
    • cgould01
    • Member since 05-06-2009, 3:38 PM
    • Posts 19

    The link you gave is for aspx web pages, will this example work for a windows form app?  I am assuming that it will.

     

    On another note: The other example still does not work.  When I did a quick watch;  The row count is coming up 0, which is telling me that there is nothing in the table.  However, I know that there is one entry in the table, because I was able to view the user in the same program under my add user form.  I am at a loss as to why it can't seem to pull the information from the table.

     

    Hans_v let me know if you think that will work for a windows form...

     

     

    Thanks 

  • Re: Access data from a table in Access 2000 Database programmicly

    06-25-2009, 12:42 PM
    • Star
      8,280 point Star
    • hans_v
    • Member since 01-29-2007, 9:03 PM
    • Posts 1,423

    cgould01:
    Hans_v let me know if you think that will work for a windows form...
     

    I believe that this will only work for ASP.NET. But If you are asking about Windows development, you're on the wrong forum, because this forum is, like the URL is saying, for ASP.NET only!

    http://windowsclient.net/default.aspx

  • Re: Access data from a table in Access 2000 Database programmicly

    06-25-2009, 1:55 PM
    • Member
      4 point Member
    • cgould01
    • Member since 05-06-2009, 3:38 PM
    • Posts 19

    I wanted to let everyone know what I did to fix the problem:

    Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'BatchAideDataSet.sa' table. You can move, or remove it, as needed.
            Me.SaTableAdapter.Fill(Me.BatchAideDataSet.sa)
    
        End Sub
    
    
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
            Dim MyDatarows() As System.Data.DataRow = BatchAideDataSet.Tables("sa").Select("Username='CGOULD'")
            Dim MyInfo As String = MyDatarows(0).Item(2)
            MsgBox(MyInfo)
            Me.Close()
        End Sub
     
    The problem that I was having and what I have learned is that when you copy a dataset from one form to another it will not add the " on load" event for you.
     
    Does wonders when you add the line above to your form load event :P~


     

Page 1 of 1 (10 items)