Solved

Winforms saving form data using a data class

Posted on 2008-10-22
6
348 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
[X]
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
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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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