Question Store dating in windows app

roary86

Member
Joined
Mar 16, 2009
Messages
12
Programming Experience
1-3
I'm new to desktop applications. My goal is simple: A user enters in their first name, last name, email address and phone number. They hit submit, it verifies they entered in proper data and then it stores the data into a local db inside VS. I have never used data sets and table adapaters before so I'm having trouble storing the data into the local DB can anyone help? Thanks
 
Perhaps you could tell/show us exactly what you are currently doing and what happens when you do it. There's no point our providing an end to end explanation when you probably already have most of the pieces in place.
 
Well that I have so far is the project with a windows form that has a First Name, Last Name, Email Address, and Phone Number text boxes with a submit button.

I also have a .MDF file that I created inside Visual Studio 2008.

I also have a DataSet.

My goal is to use the DataSet to insert the information of what the user has entered into the text boxes.

Thats the part im stumped on is how to take that information and use the data set to insert it into the DB.

I hope this exlpains more.
 
You need to first add some components to your form from the ToolBox. You'll need an instance of your DataSet, an instance of the TableAdapter that corresponds to the table that contains the data you want to display, and you'll need a BindingSource.

Select the BindingSource in the designer and open the Properties window. Select the DataSet as the DataSource and set the DataMember to the appropriate table.

Select a TextBox and open the Properties window. Expand the DataBindings item and select the Text property. Select the appropriate column from the BindingSource as the value.

Create a Load event handler for the form and, in it, call Fill on your TableAdapter and pass the appropiate table from your DataSet.

Now run the application and show the form and you'll see the first record from your result set.
 
Thanks for the help but, I'm not wanting to display what is in the database. I'm trying to INSERT into the database.

I have the DataSet, TableAdapter, and BindingSource and all the values from the text boxes set to variables. Now I just need to figure out how to insert those valuse into the DB.

Dim usersDataSet As New Database1DataSet
Dim usersTableAdapter As New Database1 _ DataSetTableAdapters.UsersTableAdapter
Dim usersBindingSource As New BindingSource

Dim FirstName As String
FirstName = Me.txtFName.Text
Dim LastName As String
LastName = Me.txtLName.Text
Dim EmailAddress As String
EmailAddress = Me.txtEmailAddress.Text
Dim clientPhone As String
clientPhone = Me.txtPhone1.Text + Me.txtPhone2.Text + Me.txtPhone3.Text
 
To add a new record to your DataTable you call AddNew on the BindingSource. You then populate the TextBoxes and the data is automatically pushed to the DataTable. Call EndEdit to commit the data and then call Update on your TableAdapter to save the changes to the database.
 
so this is what I have on the btnSubmit_click method

Dim clientsDataSet As WinAppsDataSet
Dim clientsTableAdapter As WinAppsDataSetTableAdapters.ClientsTableAdapter
Dim clientsBindingSource As BindingSource

Dim FirstName As String
FirstName = Me.txtFName.Text
Dim LastName As String
LastName = Me.txtLName.Text
Dim EmailAddress As String
EmailAddress = Me.txtEmailAddress.Text
Dim clientPhone As String
clientPhone = Me.txtPhone1.Text + Me.txtPhone2.Text + Me.txtPhone3.Text


clientsBindingSource.AddNew()


clientsBindingSource.EndEdit()
clientsTableAdapter.Update(clientsDataSet.Clients)
 
Read the DW2 link in my signature, section on Creating a Simple Data App.. You're basically at the stage where you should simply open the Data Sources window and drag the text boxes therein onto your form; VS will bind them to your dataset for you
 
Let Me add to that: Root level of the code:
VB.NET:
  'Module level variables
    Private AclientDataSet As WinAppsDataSet
    Private AWinAppsTableAdapter As WinAppsDataSetTableAdapters.ClientsTableAdapter
    Private WithEvents AWinAppsBindingSource As BindingSource

btinSubmit_Click
VB.NET:
        AclientDataSet = New WinAppsDataSet
        AWinAppsTableAdapter = New WinAppsDataSetTableAdapters.ClientsTableAdapter
        AWinAppsTableAdapter.Fill(AclientDataSet.Clients)


        AWinAppsBindingSource = New BindingSource
        With AWinAppsBindingSource
            .DataSource = AclientDataSet
            .DataMember = "AclientDataSet"
        End With

        Dim FirstName As String
        FirstName = Me.txtFName.Text
        Dim LastName As String
        LastName = Me.txtLName.Text
        Dim EmailAddress As String
        EmailAddress = Me.txtEmailAddress.Text
        Dim clientPhone As String
        clientPhone = Me.txtPhone1.Text + Me.txtPhone2.Text + Me.txtPhone3.Text

        Me.txtFName.DataBindings.Add("text", AWinAppsBindingSource, "FirstName")

        AWinAppsBindingSource.AddNew()

        AWinAppsBindingSource.EndEdit()
        AWinAppsTableAdapter.Update(AclientDataSet.Clients)

        ErrorProvider1.Clear()
 
Read the DW2 link in my signature, section on Creating a Simple Data App.. You're basically at the stage where you should simply open the Data Sources window and drag the text boxes therein onto your form; VS will bind them to your dataset for you

The links in your signature do not work.
 
Data Walkthroughs

Msdn went through an update overnight. All links starting with msdn2.microsoft.com appear to use msdn.microsoft.com now. Unfortunately they weren't kind enough to provide a redirect to the new location.
 
Read the DW2 link in my signature, section on Creating a Simple Data App.. You're basically at the stage where you should simply open the Data Sources window and drag the text boxes therein onto your form; VS will bind them to your dataset for you

I'm not wanting to display the data. I'm just wanting to insert the data into the database.
 
Okay I have my data inserting into the DB but something very strange is happening. When I format the labels and text boxes, changing the font color, size, etc. When I store the information it deletes all the previous data and overwrites everything each time. It's only storing the latest data. So It's only storing 1 row.????!?!!!
 
The links in your signature do not work.

They do for me; what do you see?


I can't quite understand why you'd go to all the trouble of declaring your datasets at class level in your own code, and then making a new TA, new DataSet, filling it and then binding it every time..

Why not just get VS to do it all for you once (drag the relevant item from the Data Sources window to your form)
 
Back
Top