Thanks for the help!
I use two data adapters; the first is used to great the data grid. After a
record is selected via the DataGrid or a lookup field and button to
execute the value in the field and find the record from a second data
adapter that was greated with a "SELECT *".
Onve I find the DataViewRow within the second data adapter I pass it in
the Public class to all the forms. I can get data to and get back into the
dataviewrow without any incident. I'm assuming that at any point in any of
the screens I could do the update from the DataViewRow (I'd have no idea
how to do this). My goes would be that an "Update" button would reside on
each form and if the users clicks the Update button an UpdateFlag in the
Public CLass would be set.
At that point I want to check the Update Flag and keep going backwards
until I get to the main form and perform an update using the values in the
DataViewRow.
I than stay in the main form and the user can select another item and go
from there.
Steve
Private Sub PopulateStoreGrid()
Dim conn As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
source=C:\BMActivityReporting.mdb;Persist Security Info=False")
Dim sSQL As String = "select BM_NUMBER, STORE_NUMBER, STORE, SHIP_ADDRESS1
as ADDRESS, SHIP_CITY as CITY, SHIP_ST as STATE from BENMOORETABLE"
Dim sSQL2 As String = "select * from BENMOORETABLE"
conn.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter(sSQL, conn)
Dim da2 As New System.Data.OleDb.OleDbDataAdapter(sSQL2, conn)
Try
da.Fill(myDS, "BENMOOR1")
iCount = myDS.Tables("BENMOOR1").Rows.Count
da2.Fill(myDS, "BENMOOR2")
myDV = myDS.Tables("BENMOOR2").DefaultView
DataGrid1.DataSource = myDS
DataGrid1.DataMember = "BENMOOR1"
Dim irow As Integer
Dim icol As Integer
irow = 0
DataGrid1.Select(irow)
Dim sStore As String = CType(DataGrid1.Item(irow, 1), String)
myDV.Sort = "STORE_NUMBER"
Dim rowIndex As Integer = myDV.Find(sStore)
Me.LegalName1.Text = myDV(rowIndex)("LEGAL_NAME_LINE1").ToString()
Me.LegalName2.Text = myDV(rowIndex)("LEGAL_NAME_LINE2").ToString()
Me.StoreOwner.Text = myDV(rowIndex)("STORE_OWNER").ToString()
Me.PhoneNumber.Text = myDV(rowIndex)("PHONE_NUMBER").ToString()
Me.LegalName3.Text = myDV(rowIndex)("LEGAL_NAME_LINE3").ToString()
Me.LegalName4.Text = myDV(rowIndex)("LEGAL_NAME_LINE4").ToString()
Me.EMailAddress.Text = myDV(rowIndex)("E-MAIL_ADDRESS").ToString()
'UpdateScreen(irow)
Catch ex As Exception
MessageBox.Show("Failed to connect to data source")
Finally
conn.Close()
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
myFormLibrary.StoreInformation1 = Me
myFormLibrary.StoreInformation2 = Me
myFormLibrary.StoreInformation4 = Me
myFormLibrary.StoreInformation4 = Me
myFormLibrary.StoreInformation5 = Me
myFormLibrary.StoreInformation6 = Me
myFormLibrary.StoreInformation7 = Me
PopulateStoreGrid()
'
' Create a Grid Table Style. Map it to the "Customers" Table.
'
Dim aGridTableStyle As New DataGridTableStyle
aGridTableStyle.MappingName = "BENMOOR1"
'
' Create GridColumnStyle objects for the grid columns
'
Dim aCol1 As New DataGridTextBoxColumn
Dim aCol2 As New DataGridTextBoxColumn
Dim aCol3 As New DataGridTextBoxColumn
Dim aCol4 As New DataGridTextBoxColumn
Dim aCol5 As New DataGridTextBoxColumn
Dim aCol6 As New DataGridTextBoxColumn
'
With aCol1
.HeaderText = "BM#"
.MappingName = "BM_NUMBER"
.Width = 45
.TextBox.Enabled = False
End With
'
' Set column 2's caption, width and disable editing.
'
With aCol2
.MappingName = "STORE_NUMBER"
.HeaderText = "Store#"
.Width = 40
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With aCol3
.MappingName = "STORE"
.HeaderText = "Store Name"
.Width = 200
.Alignment = HorizontalAlignment.Left
' .NullText = ""
.TextBox.Enabled = False
End With
With aCol4
.MappingName = "ADDRESS"
.HeaderText = "Store Address"
.Width = 200
.Alignment = HorizontalAlignment.Left
'.NullText = "0"
.TextBox.Enabled = False
'.Format = "#0.00"
End With
With aCol5
.MappingName = "CITY"
.HeaderText = "CIty"
.Width = 100
.Alignment = HorizontalAlignment.Left
'.NullText = "0"
.TextBox.Enabled = False
'.Format = "#0.00"
End With
With aCol6
.MappingName = "STATE"
.HeaderText = "St."
.Width = 30
.Alignment = HorizontalAlignment.Left
'.NullText = "0"
.TextBox.Enabled = False
'.Format = "#0.00"
End With
'
' Add the GridColumnStyles to the DataGrid's Column Styles collection.
'
With aGridTableStyle.GridColumnStyles
.Add(aCol1)
.Add(aCol2)
.Add(aCol3)
.Add(aCol4)
.Add(aCol5)
.Add(aCol6)
End With
'
' Add the GridColumnStyles to the aGridTableStyle.
'
DataGrid1.TableStyles.Add(aGridTableStyle)
End Sub
Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.DoubleClick
Dim StoreNo1 As String
Dim Storeno2 As String
Dim checkarea As String
Dim irow As Integer = DataGrid1.CurrentCell.RowNumber
Dim sStore As String = CType(DataGrid1.Item(irow, 1), String)
myDV.Sort = "STORE_NUMBER"
Dim rowIndex As Integer = myDV.Find(sStore)
Dim frminfo As New StoreInformation
'Set up values for storeinfor screen
frminfo.LegalName1.Text = myDV(rowIndex)("LEGAL_NAME_LINE1").ToString()
frminfo.LegalName2.Text = myDV(rowIndex)("LEGAL_NAME_LINE2").ToString()
frminfo.StoreOwner.Text = myDV(rowIndex)("STORE_OWNER").ToString()
frminfo.PhoneNumber.Text = myDV(rowIndex)("PHONE_NUMBER").ToString()
frminfo.LegalName3.Text = myDV(rowIndex)("LEGAL_NAME_LINE3").ToString()
frminfo.LegalName4.Text = myDV(rowIndex)("LEGAL_NAME_LINE4").ToString()
frminfo.EMailAddress.Text = myDV(rowIndex)("E-MAIL_ADDRESS").ToString()
StoreNo1 = myDV(rowIndex)("STORE_NUMBER").ToString()
Storeno2 = myDV(rowIndex)("PARENT_STORE_NUMBER").ToString()
frminfo.StoreNo.Text = StoreNo1 & " / " & Storeno2
StoreNo1 = myDV(rowIndex)("BM_NUMBER").ToString()
Storeno2 = myDV(rowIndex)("CURR").ToString()
frminfo.BMNUMBER.Text = StoreNo1 & " / " & Storeno2
frminfo.MailToName.Text = myDV(rowIndex)("MAIL_NAME").ToString()
frminfo.MailToAdd1.Text = myDV(rowIndex)("MAIL_ADDRESS1").ToString()
frminfo.MailToAdd2.Text = myDV(rowIndex)("MAIL_ADDRESS2").ToString()
frminfo.MailToCity.Text = myDV(rowIndex)("MAIL_CITY").ToString()
frminfo.MailToState.Text = myDV(rowIndex)("MAIL_ST").ToString()
frminfo.MailToZip.Text = myDV(rowIndex)("MAIL_ZIPCODE").ToString()
frminfo.ShipToName.Text = myDV(rowIndex)("STORE").ToString()
frminfo.ShipToAdd1.Text = myDV(rowIndex)("SHIP_ADDRESS1").ToString()
frminfo.ShipToAdd2.Text = myDV(rowIndex)("SHIP_ADDRESS2").ToString()
frminfo.ShipToCity.Text = myDV(rowIndex)("SHIP_CITY").ToString()
frminfo.ShipToCounty.Text = myDV(rowIndex)("COUNTY").ToString()
frminfo.ShipToState.Text = myDV(rowIndex)("SHIP_ST").ToString()
frminfo.ShipToZip.Text = myDV(rowIndex)("MAIL_ZIPCODE").ToString()
frminfo.SupplierRepTop1.Text = myDV(rowIndex)("PAINT_TERRITORY_MANAGE_
NAME").ToString()
frminfo.SupplierRepTop2.Text =
myDV(rowIndex)("REGIONAL_MANAGER").ToString()
frminfo.SupplierRepTop3.Text =
myDV(rowIndex)("RETAIL_BUSINES_MANAGER").ToString()
frminfo.SupplierRepTop4.Text =
myDV(rowIndex)("RETAIL_DEVELOPMEN_MANAGER1").ToString()
frminfo.SupplierRepTop5.Text = myDV(rowIndex)("RETAI_DEVELOPMENT_MANAGE
2").ToString()
Dim frminfo1 As New StoreInformation1
'Set up values for storeinform1 screen
frminfo1.LegalName1.Text = myDV(rowIndex)("LEGAL_NAME_LINE1").ToString()
frminfo1.LegalName2.Text = myDV(rowIndex)("LEGAL_NAME_LINE2").ToString()
frminfo1.StoreOwner.Text = myDV(rowIndex)("STORE_OWNER").ToString()
frminfo1.PhoneNumber.Text = myDV(rowIndex)("PHONE_NUMBER").ToString()
frminfo1.LegalName3.Text = myDV(rowIndex)("LEGAL_NAME_LINE3").ToString()
frminfo1.LegalName4.Text = myDV(rowIndex)("LEGAL_NAME_LINE4").ToString()
frminfo1.EMailAddress.Text = myDV(rowIndex)("E-MAIL_ADDRESS").ToString()
StoreNo1 = myDV(rowIndex)("STORE_NUMBER").ToString()
Storeno2 = myDV(rowIndex)("PARENT_STORE_NUMBER").ToString()
frminfo1.StoreNo.Text = StoreNo1 & " / " & Storeno2
StoreNo1 = myDV(rowIndex)("BM_NUMBER").ToString()
Storeno2 = myDV(rowIndex)("CURR").ToString()
frminfo1.BMNUMBER.Text = StoreNo1 & " / " & Storeno2
frminfo1.ApprovalDate.Text = myDV(rowIndex)("APPROVAL_DATE").ToString()
frminfo1.Vision21Rank.Text = myDV(rowIndex)("VISION21_RANK").ToString()
frminfo1.NoBranches.Text = myDV(rowIndex)("NUMBER_BRANCHES").ToString()
frminfo1.ComputerType.Text = myDV(rowIndex)("COMPUTER_TYPE").ToString()
frminfo1.CYL.Text = myDV(rowIndex)("CYL").ToString()
frminfo1.TotBldgSF.Text = myDV(rowIndex)("TOTAL_BLDG_SF").ToString()
frminfo1.RetailHDWSF.Text = myDV(rowIndex)("RET_ HDW_SF").ToString()
frminfo1.PaintDeptSF.Text = myDV(rowIndex)("PNT_DEPT_SF").ToString()
frminfo1.PaintComputer.Text = myDV(rowIndex)("PAINT_COMPUTER").ToString()
frminfo1.PrattLambertOSO.Text =
myDV(rowIndex)("PRATT_LAMBERT_OSO_DATE").ToString()
checkarea = myDV(rowIndex)("BEHR").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(0, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(0, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("BEN_MOOR").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(1, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(1, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("CALIF").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(2, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(2, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("COLONY").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(3, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(3, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("DEVOE").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(4, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(4, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("DUTCH_BOY").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(5, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(5, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("FULLER_ O_BRIEN").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(6, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(6, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("GLIDDEN").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(7, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(7, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("LUCITE").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(8, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(8, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("MARTIN_SENOUR").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(9, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(9, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("OLYMPIC").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(10, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(10, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("OTHER_PAINT").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(11, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(11, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("PITTS").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(12, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(12, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("PORTERS").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(13, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(13, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("PPG").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(14, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(14, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("PRATT").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(15, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(15, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("RALPH_LAUREN").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(16, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(16, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("VALSPAR").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(17, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(17, CheckState.Unchecked)
End If
checkarea = myDV(rowIndex)("VAN_SICKLE").ToString()
If checkarea = "Y" Then
frminfo1.CheckedListBox1.SetItemCheckState(18, CheckState.Checked)
Else
frminfo1.CheckedListBox1.SetItemCheckState(18, CheckState.Unchecked)
End If
frminfo.myDVR = myDV(rowIndex) 'or myDV.Item(rowIndex)
frminfo.Show()
End Sub
I know there is a lot of code here; hopefully someone understands what I'm
doing and I'm not wasting lots of efforts on something that could be done
easily.
From the most novice VB.NET 2003 (maybe 5 weeks self taught).
THanks,
Steve
Cor Ligthert said:
Stephen,
You have given a lot of information and still it is not easy to help you.
Therefore some explanations.
A datarowview is a view on a datarow not to real datarow. You can get it
by
Datarowview.row
If you do an update than you can do using the DataAdapter a datarow,
there is nothing wrong with.
If you need more information, because we are here very basic.
- did you generate the dataadapter (and with that the update commands)
- what controls did you use
- did you use databinding
I hope this helps sofar,
Cor
Stephen Plotnick said:
I'm very new to VB.NET 2003
Here is what I have accomplished:
MainSelectForm - Selects an item
In a public class I pass a DataViewRow to
ItemInformation1 Form
ItemInformation2 Form
.
.
ItemInformation7 Form
I am able to get from the DataViewRow
I am able to put data back into the DataViewRow
As I go Forward and Backwards between the ItemInformationForm[1-7] all
the data I change is available and working
I feel pretty good about my first attempt to VB.NET
Now what I want to do:
Setup a button on all ItemInformation[1-7] Forms to do an update
In the public class setup a variable that I can change when clicking on
the Update button to denote an update is needed
From within MainSelectForm do the update from the DataViewRow in the
public class
My questions are:
1. How do I check the Update Flag? (I've migrated from COBOL where I
would be able to check the update flag in a linkage section, I do not
know how to do this in OO because I do not have control)
2. IS the a way to do an SQL Update via the DataViewRow without having
to do the Update listing all the fields and the WHERE clause, I have
over 100 fields?
3. I should be able to click an Update button from within any Form and
close Form after Form until getting back to MainSelectForm where the
Update would occur
Any assistance would be greatly apprecited,
Thanks,