Solved

Referencing a (dataset variable in code)

Posted on 2015-02-02
3
157 Views
Last Modified: 2015-02-02
vs2012 vb.net
Here's me code:
    Public Sub btnApply_Click(sender As Object, e As EventArgs) Handles btnApply.Click

        Dim frm As New RO_PartsL1
        Dim dstest As System.Data.DataSet = New Database1DataSet11
        dstest.Tables("PrtsLn1").Columns.Add("Parts_QuantitySold")
        Dim i As Integer = 0
        Dim TtlPrtsSellingPriceLn1 As Decimal = 0
        Dim TtlPrtsCostLn1 As Decimal = 0

        For Each row As DataGridViewRow In DataGridView1.Rows
            Dim chkboxcell As DataGridViewCheckBoxCell = row.Cells("Parts_PutOnRO")

            If chkboxcell.Value = True Then

                Dim m_PartNum_ForRO As String = Me.Database1DataSet11.Tables("PartsInv").Rows(i).Item("Parts_Num")
                Dim m_PartDesc_ForRO As String = Me.Database1DataSet11.Tables("PartsInv").Rows(i).Item("Parts_Desc")
                Dim m_SoldQty_ForRO As Decimal = 1
                Dim m_SellingPrice_ForRO As Decimal = Me.Database1DataSet11.Tables("PartsInv").Rows(i).Item("Parts_List")
                Dim m_PartCost_ForRO As Decimal = Me.Database1DataSet11.Tables("PartsInv").Rows(i).Item("Parts_Cost")

                'Your insert query to save to database table

                Dim myDr As DataRow

                myDr = dstest.Tables("PrtsLn1").NewRow()

                myDr("Parts_Num") = m_PartNum_ForRO
                myDr("Parts_Desc") = m_PartDesc_ForRO
                myDr("Parts_QuantitySold") = m_SoldQty_ForRO

                myDr("Parts_SellingPrice") = m_SellingPrice_ForRO
                TtlPrtsSellingPriceLn1 = TtlPrtsSellingPriceLn1 + m_SellingPrice_ForRO

                myDr("Parts_Cost") = m_PartCost_ForRO
                TtlPrtsCostLn1 = TtlPrtsCostLn1 + m_PartCost_ForRO

                dstest.Tables("PrtsLn1").Rows.Add(myDr)

            End If

            i = i + 1

        Next

        If TtlPrtsSellingPriceLn1 <> 0 Then
            UpdtePrtsSellingPriceLn1(TtlPrtsSellingPriceLn1)
        Else

        End If

        If TtlPrtsCostLn1 <> 0 Then
            UpdtePrtsCostLn1(TtlPrtsCostLn1)
        Else

        End If

        'TODO: This line of code loads data into the 'Database1DataSet11.PrtsLn1' table. You can move, or remove it, as needed.
        frm.DGV_Line1.DataSource = dstest.Tables("PrtsLn1")
        Me.Close()
        frm.Show()
    End Sub

everything seems to be working up to here
? is when I exit the "SUB" - How do I reference the DATA IN "frm.DGV_Line1.DataSource = dstest.Tables("PrtsLn1")"
if "dstest" is a block declared VARIABLE "data in the datagridview I mean"
I don't want to declare it DSTEST as a Global variable if I don't have to.
0
Comment
Question by:MBHEY131
[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 Comments
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 500 total points
ID: 40583943
Within frm, the data would be easily accessed.  I'm not sure what DGV_Line1 is, but it probably has text that has been set by virtue of having the DataSource set.

Do you need to access that data from code in frm?  Of from code in the form that has btnApply?

If the latter, you probably need a global variable for that data element -- the string that is in dstest.Tables("PrtsLn1")"
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40584020
You don't have to make it a global variable in that all classes and assemblies within the project can access it.  Rather, you would make it global to the class it exists in.  Consider the following:
Module Module1
	Private classLevelVariable As String = "I am a class\module level variable.  I can be changed by any method in the class\module."

	Sub Main()
		Console.WriteLine(classLevelVariable)
		Method1()
		Console.WriteLine(classLevelVariable)
		Console.ReadLine()
	End Sub

	Sub Method1()
		Dim method1LevelVariable As String = "I am a method level variable.  I can only be changed within the method I am declared."
		Console.WriteLine(method1LevelVariable)
		classLevelVariable = "Method1 has changed my value."
	End Sub
End Module

Open in new window

Which produces the following output -Capture.JPG-saige-
0
 

Author Closing Comment

by:MBHEY131
ID: 40584048
don't like using Global Variables but I have to access that data from another form
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Invest in your employees with these five simple steps to improve employee engagement and retention.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
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…

627 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