Displaying Data in a seperate form

welly

New member
Joined
Mar 2, 2005
Messages
2
Programming Experience
Beginner
Hi,

I have 3 Forms from which i want to populate the thrid form with details only from a certain OrderID, i have a button that takes you too another form with options(buttons for different areas), and then from there depending on the option you choose, takes you to the third form where there are text boxes which i want populating with the OrderID from the first page.

I was told to use a property class to store the OrderID so that when the option was pushed a query could be run using that number, as im new to VB.Net, i find it hard to implement it.

Is this the way to go or is there an easier way

Can anyone help?
 
Public variables

I like to add a module to my project called PublicVariables.
I use these variables to store record id's and dates and stuff.
The nice thing about it is that all forms can access them and retrieve thier value.

Module PublicVariables

Public tCurrentPartNumber As String
Public tCurrentCustomer As String

Public iCurrentPartid As Integer

Public dStartdate As Date

Public PartFound As Boolean

End Module

then you can do things like this:
iCurrentPartid = PartGrid.Columns("Part ID").Value
tCurrentPartNumber = textbox1.text

or

SqlSelectCommand1.Parameters("@Partid").Value = iCurrentPartid
textbox1.text = tCurrentPartNumber
 
Last edited:
Thanks David.

I wasnt thinking far too complicated.

Now as im new, im having trouble executting the SQL query, im using this code but i know it must be more complicated than this.

This Code is run after a button click event

Dim sqlQueryString As String
sqlQueryString = "select * from software where ( orderID = " & OrderNo & ")"

All i want to do is run this query so that details from the software table resulting from the orderNo stored populate the textbox's i have created in the next form.
 
Try this...trying to make it easy on you

I have typical advise for new programmers, it's how I started. The dataform wizard will write the basic code for a forms underlying functions - select, add. edit and delete.


Load, Add, Update, and Delete commands can get sticky really fast. The dataform wizard does a good job creating these commands for you. If you create a form with the dataform wizard and display the table in a grid, the wizard will generate code for Load, Add, Update, and Delete.
It will create code on button events for triggering the events.
I started by letting the wizard generate the code and dataadapters/datasets for me then tweeking the code the way I like it.
I delete OLEDBAdapter and replace with SQLDataAdapter for instance. The code for the Load button remains the same, I just have to change the DataSet, DataAdapter, and Connection Names.

1. drag an SqlDataAdapter onto a form
2. Choose a connection
3. Choose USE SQL STATEMENTS
4. Hit the Query Builder button
5. Add the Software Table
6. Check all the fields seperately
7. In the Criteria column of the ID field put =@orderid
8. finish out the Query wizard

The select statement and all other statements are created. Look at the generated code and use it until you become more familiar with the syntax. Expand + Windows Form Designer generated code and check out the select statement. then you can...

add this code before the try on the btnLoad.Click event
SqlSelectCommand1.Parameters("@orderid ").Value = OrderNo


example of wizard generated code:

Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Try
Me.LoadDataSet()
Catch eLoad As System.Exception
System.Windows.Forms.MessageBox.Show(eLoad.Message)
End Try
End Sub

Public Sub LoadDataSet()
Dim objDataSetTemp As WindowsApplication2.dsSoftware1
objDataSetTemp = New WindowsApplication2.dsSoftware1
Try
Me.FillDataSet(objDataSetTemp)
Catch eFillDataSet As System.Exception
Throw eFillDataSet
End Try
Try
grdSoftware.DataSource = Nothing
objdsSoftware1.Clear()
objdsSoftware1.Merge(objDataSetTemp)
grdSoftware.SetDataBinding(objdsSoftware1, "Software")
Catch eLoadMerge As System.Exception
Throw eLoadMerge
End Try
End Sub

Public Sub FillDataSet(ByVal dataSet As WindowsApplication2.dsSoftware1)
dataSet.EnforceConstraints = False
Try
Me.OleDbConnection1.Open()
Me.OleDbDataAdapter1.Fill(dataSet)
Catch fillException As System.Exception
Throw fillException
Finally
dataSet.EnforceConstraints = True
Me.OleDbConnection1.Close()
End Try
End Sub


You should be able to change OleDB to SQL and objdsSoftware1 to dsSoftware1 and take off running.

Let me know if it helps...
 
Last edited:
Back
Top