Go Premium for a chance to win a PS4. Enter to Win


Winforms saving form data using a data class

Posted on 2008-10-22
Medium Priority
Last Modified: 2013-11-07
Hi All

I'm new to win forms , but have experience of ASP.net, and I guess my problem comes from the differences between the 2.

I have written a data access layer and a methos to save data back to my SQL Server 2005 database by calling a storedProc.

I also have a win form with several fields, how to I link the 2. I could use create a data source and let studio do the hardwork, but I would like to use my class if I can.

Question by:Andy Green
  • 3
  • 3
LVL 27

Expert Comment

ID: 22788227
Is your Data Access class in a DLL?  If so, just add a reference to it, and away you go...  If not, you can put it in a DLL, or just add the class to your project.  The preferred method is adding it to a DLL.


Author Comment

by:Andy Green
ID: 22788441
Yes I have a dll, but how do I bind to it.

I have a form with text fields a data access layer class, and the database.

How do I assign the text fiels values to the fields in the DAL

LVL 27

Expert Comment

ID: 22788542
Is your DAL returning a table, a generic list, or something?

You can bind to it:
Dim table as DataTable  'example only

     Me.TextBox1.DataBindings.Add("Text", table, "My Column Name")

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.


Author Comment

by:Andy Green
ID: 22788717
This is it.
Public Sub InsertTestRecord(ByVal ReferL_RefNo As String, ByVal ReferL_Date As DateTime, ByVal Con_Abbr As String, ByVal Spec_Abbr As String, ByVal Forename As String, ByVal Surname As String, ByVal Gender As String, ByVal PAS_ID As String, ByVal Printed As Boolean, ByVal Status As String, ByVal LiveTest As Boolean)

            Dim sqlCmd As New SqlCommand()
            sqlCmd.CommandType = CommandType.StoredProcedure
            sqlCmd.CommandText = "spInsertTestRecord"
            sqlCmd.Connection = Me._sqlConn

            Dim sqlPrmReferL_RefNo As New SqlParameter("@ReferL_RefNo", ReferL_RefNo)
            Dim sqlPrmReferL_Date As New SqlParameter("@ReferL_Date", ReferL_Date)
            Dim sqlPrmCon_Abbr As New SqlParameter("@Con_Abbr", Con_Abbr)
            Dim sqlPrmSpec_Abbr As New SqlParameter("@Spec_Abbr", Spec_Abbr)
            Dim sqlPrmForename As New SqlParameter("@Forename", Forename)
            Dim sqlPrmSurname As New SqlParameter("@Surname", Surname)
            Dim sqlPrmGender As New SqlParameter("@Gender", Gender)
            Dim sqlPrmPAS_ID As New SqlParameter("@PAS_ID", PAS_ID)
            Dim sqlPrmPrinted As New SqlParameter("@Printed", Printed)
            Dim sqlPrmStatus As New SqlParameter("@Status", Status)
            Dim sqlPrmLiveTest As New SqlParameter("@LiveTest", LiveTest)



        Catch ex As Exception
            Throw ex
        End Try

    End Sub

I see how to join the text box values to the column names, how would I perform the actual write back.

Is my class wrong in that it doesn't return a table or dataset.

LVL 27

Accepted Solution

VBRocks earned 2000 total points
ID: 22788780
You're going to have to pass the values to the Sub.

What's the name of the class?  (we'll pretend it's "Class1")

Dim c as New Class1()
c.InsertTestRecord(ReferL_RefNo_TextBox.Text, CDate(ReferL_Date_TextBox.Text), Con_Abbr_TextBox.Text, etc...)


Author Closing Comment

by:Andy Green
ID: 31508688
Excellent thank you.


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question