Winforms saving form data using a data class

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

I'm new to win forms , but have experience of, 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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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")

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.


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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GUID's in SQL Server 4 31
Error in Visual Project 10 49
Building Collections of Objects based on their Tag Property 33 54 searchandselect 12 17
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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