Solved

Winforms saving form data using a data class

Posted on 2008-10-22
6
324 Views
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.

Andy
0
Comment
Question by:Andy Green
  • 3
  • 3
6 Comments
 
LVL 27

Expert Comment

by:VBRocks
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.

0
 
LVL 3

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

Andy
0
 
LVL 27

Expert Comment

by:VBRocks
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")

0
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.

 
LVL 3

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)

        Try
            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)

            sqlCmd.Parameters.Add(sqlPrmReferL_RefNo)
            sqlCmd.Parameters.Add(sqlPrmReferL_Date)
            sqlCmd.Parameters.Add(sqlPrmCon_Abbr)
            sqlCmd.Parameters.Add(sqlPrmSpec_Abbr)
            sqlCmd.Parameters.Add(sqlPrmForename)
            sqlCmd.Parameters.Add(sqlPrmSurname)
            sqlCmd.Parameters.Add(sqlPrmGender)
            sqlCmd.Parameters.Add(sqlPrmPAS_ID)
            sqlCmd.Parameters.Add(sqlPrmPrinted)
            sqlCmd.Parameters.Add(sqlPrmStatus)
            sqlCmd.Parameters.Add(sqlPrmLiveTest)

            sqlCmd.ExecuteNonQuery()

        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.

Andy
0
 
LVL 27

Accepted Solution

by:
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...)

0
 
LVL 3

Author Closing Comment

by:Andy Green
ID: 31508688
Excellent thank you.

Andy
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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