Solved

Winforms saving form data using a data class

Posted on 2008-10-22
6
300 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Author Comment

by:Andy Green
Comment Utility
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
Comment Utility
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
Comment Utility
Excellent thank you.

Andy
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now