Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

An Urgent Cry For Help

  • 13-04-2005 2:31pm
    #1
    Closed Accounts Posts: 579 ✭✭✭


    I have been trying to link a database to my project for over 3 weeks now and I am no closer to figuring it out!, I've been to numerous web sites and none have helped, I've gotten 4 books on ADO.Net and still no Database!...I'm really stuck now...What I want to do is link up my (Access) Database to my VB.Net Project. Any Help would be greatly appreciated!..At this stage I'd almost pay someone to do it for me if it was so morally wrong lol

    Thanks in advance


Comments

  • Registered Users, Registered Users 2 Posts: 2,758 ✭✭✭Peace


    Are you just venting or are you going to post up you code and let us help you out.


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    What exactly are you trying to do with the database and where are you failing ? Are you using Visual Studio or something else ? Most books will have sample code that will work with the northwind database or some other database that they will show you how to create. Have you gotten any of them to work ?


  • Closed Accounts Posts: 579 ✭✭✭Magnolia_Fan


    I'd post my code but I'm pretty sure its all ballacks, I'm using Visual Studios, I've been getting bits and pieces from different books and trying to piece them together. If someone maybe(and I know this is asking alot) could tell me maybe how to set up a username and password and then reading them I could figure out my other 2 main database functions


  • Closed Accounts Posts: 579 ✭✭✭Magnolia_Fan


    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Me.BindingContext(objdsLogin, "Login").CancelCurrentEdit()

    End Sub
    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    If (Me.BindingContext(objdsLogin, "Login").Count > 0) Then
    Me.BindingContext(objdsLogin, "Login").RemoveAt(Me.BindingContext(objdsLogin, "Login").Position)

    End If

    End Sub
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    Try
    'Clear out the current edits
    Me.BindingContext(objdsLogin, "Login").EndCurrentEdit()
    Me.BindingContext(objdsLogin, "Login").AddNew()
    Catch eEndEdit As System.Exception
    System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
    End Try


    End Sub
    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    Try
    Try
    'Clear out the current edits
    Me.BindingContext(objdsLogin, "Login").EndCurrentEdit()
    Me.BindingContext(objdsLogin, "Login").AddNew()
    Catch eEndEdit As System.Exception
    System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
    End Try

    'Attempt to update the datasource.
    Me.UpdateDataSet()
    Catch eUpdate As System.Exception
    ' Add your error handling code here.
    'Display error message, if any.
    System.Windows.Forms.MessageBox.Show(eUpdate.Message)
    End Try


    End Sub
    Private Sub btnCancelAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Me.objdsLogin.RejectChanges()

    End Sub
    Public Sub UpdateDataSet()
    'Create a new dataset to hold the changes that have been made to the main dataset.
    Dim objDataSetChanges As Project1.dsLogin = New Project1.dsLogin
    'Stop any current edits.
    Me.BindingContext(objdsLogin, "Login").EndCurrentEdit()
    'Get the changes that have been made to the main dataset.
    objDataSetChanges = CType(objdsLogin.GetChanges, Project1.dsLogin)
    'Check to see if any changes have been made.
    If (Not (objDataSetChanges) Is Nothing) Then
    Try
    'There are changes that need to be made, so attempt to update the datasource by
    'calling the update method and passing the dataset and any parameters.
    Me.UpdateDataSource(objDataSetChanges)
    objdsLogin.Merge(objDataSetChanges)
    objdsLogin.AcceptChanges()
    Catch eUpdate As System.Exception
    'Add your error handling code here.
    Throw eUpdate
    End Try
    'Add your code to check the returned dataset for any errors that may have been
    'pushed into the row object's error.
    End If

    End Sub
    Public Sub LoadDataSet()
    'Create a new dataset to hold the records returned from the call to FillDataSet.
    'A temporary dataset is used because filling the existing dataset would
    'require the databindings to be rebound.
    Dim objDataSetTemp As Project1.dsLogin
    objDataSetTemp = New Project1.dsLogin
    Try
    'Attempt to fill the temporary dataset.
    Me.FillDataSet(objDataSetTemp)
    Catch eFillDataSet As System.Exception
    'Add your error handling code here.
    Throw eFillDataSet
    End Try
    Try
    'Empty the old records from the dataset.
    objdsLogin.Clear()
    'Merge the records into the main dataset.
    objdsLogin.Merge(objDataSetTemp)
    Catch eLoadMerge As System.Exception
    'Add your error handling code here.
    Throw eLoadMerge
    End Try

    End Sub
    Public Sub UpdateDataSource(ByVal ChangedRows As Project1.dsLogin)
    Try
    'The data source only needs to be updated if there are changes pending.
    If (Not (ChangedRows) Is Nothing) Then
    'Open the connection.
    Me.OleDbConnection1.Open()
    'Attempt to update the data source.
    OleDbDataAdapter1.Update(ChangedRows)
    End If
    Catch updateException As System.Exception
    'Add your error handling code here.
    Throw updateException
    Finally
    'Close the connection whether or not the exception was thrown.
    Me.OleDbConnection1.Close()
    End Try

    End Sub
    Public Sub FillDataSet(ByVal dataSet As Project1.dsLogin)
    'Turn off constraint checking before the dataset is filled.
    'This allows the adapters to fill the dataset without concern
    'for dependencies between the tables.
    dataSet.EnforceConstraints = False
    Try
    'Open the connection.
    Me.OleDbConnection1.Open()
    'Attempt to fill the dataset through the OleDbDataAdapter1.
    Me.OleDbDataAdapter1.Fill(dataSet)
    Catch fillException As System.Exception
    'Add your error handling code here.
    Throw fillException
    Finally
    'Turn constraint checking back on.
    dataSet.EnforceConstraints = True
    'Close the connection whether or not the exception was thrown.
    Me.OleDbConnection1.Close()
    End Try

    End Sub


  • Registered Users, Registered Users 2 Posts: 4,276 ✭✭✭damnyanks


    If you are using Visual Studio.net just goto the data components. It's easy enough to work out after a bit of tinkering :)


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,758 ✭✭✭Peace


    Ok,

    Take a step back... there is a halla lot of code up there for someone who hasn't been able to connect to a database.

    IMO the basic steps to retrieving information are:
    1. the connection (create & open it)
    2. retrieve the information. (you have a couple of options - DataReader/DataAdapter)

    Step 1 would be something like :

    SqlConnection conSql = new SqlConnection("Inster your connection string");
    try
    {
            conSql.Open();
    }
    catch(Exception ex)
    {
            MessageBox.Show(ex.message);
    }
    

    The above code simply declares and opens connection. If there's an error then it will be popped up on screen.

    Its basic, but its good. (Its also in C# but you won't have any problems changing it to VB.Net)


  • Registered Users, Registered Users 2 Posts: 2,300 ✭✭✭PixelTrawler


    Peace wrote:
    Ok,



    SqlConnection conSql = new SqlConnection("Inster your connection string");
    try
    {
            conSql.Open();
    }
    catch(Exception ex)
    {
            MessageBox.Show(ex.message);
    }
    


    The above is spot on and if you are unsure how to write the connection string try either http://www.connectionstrings.com or http://www.carlprothman.net/Default.aspx?tabid=81 for a list of all connection types


  • Closed Accounts Posts: 579 ✭✭✭Magnolia_Fan


    O.k thanks for the help, I now have the database connected and I'm able to load info into some of my fields(Have my Connection, Adapter and Dataset created and the text boxes etc. are linked by the binding property) However I now have a new problem, linking my Checkboxes and Radio Buttons...I'm going to search now but if you guys know a solution feel free to help me even more :) I know I'll need it when it comes time to generate search anyways


Advertisement