For example:
When I change the roomno in the first column in the Datagrid to something
else, I would like to check if that value exist before I update the DB. When
I check it agains the DataView I created, the DataView.count = 1 (it should
be 0).
I am including the whole code from my form. The button is only there to
test, hopefully I can put the good code into the cellChanged event.
Public Class Form1
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents OleDb As System.Data.Ole Db.OleDbDataAda pter
Friend WithEvents OleDbSelectComm and1 As System.Data.Ole Db.OleDbCommand
Friend WithEvents OleDbInsertComm and1 As System.Data.Ole Db.OleDbCommand
Friend WithEvents OleDbUpdateComm and1 As System.Data.Ole Db.OleDbCommand
Friend WithEvents OleDbDeleteComm and1 As System.Data.Ole Db.OleDbCommand
Friend WithEvents OleDbConnection 1 As System.Data.Ole Db.OleDbConnect ion
Friend WithEvents Ds1 As Datagrid_Test.D S
Friend WithEvents DataGrid1 As System.Windows. Forms.DataGrid
Friend WithEvents OleDb2 As System.Data.Ole Db.OleDbDataAda pter
Friend WithEvents OleDbSelectComm and2 As System.Data.Ole Db.OleDbCommand
Friend WithEvents OleDbInsertComm and2 As System.Data.Ole Db.OleDbCommand
Friend WithEvents OleDbUpdateComm and2 As System.Data.Ole Db.OleDbCommand
Friend WithEvents OleDbDeleteComm and2 As System.Data.Ole Db.OleDbCommand
Friend WithEvents Label1 As System.Windows. Forms.Label
Friend WithEvents Label2 As System.Windows. Forms.Label
Friend WithEvents Label3 As System.Windows. Forms.Label
Friend WithEvents Button1 As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.OleDb = New System.Data.Ole Db.OleDbDataAda pter
Me.OleDbDeleteC ommand1 = New System.Data.Ole Db.OleDbCommand
Me.OleDbConnect ion1 = New System.Data.Ole Db.OleDbConnect ion
Me.OleDbInsertC ommand1 = New System.Data.Ole Db.OleDbCommand
Me.OleDbSelectC ommand1 = New System.Data.Ole Db.OleDbCommand
Me.OleDbUpdateC ommand1 = New System.Data.Ole Db.OleDbCommand
Me.Ds1 = New Datagrid_Test.D S
Me.DataGrid1 = New System.Windows. Forms.DataGrid
Me.OleDb2 = New System.Data.Ole Db.OleDbDataAda pter
Me.OleDbDeleteC ommand2 = New System.Data.Ole Db.OleDbCommand
Me.OleDbInsertC ommand2 = New System.Data.Ole Db.OleDbCommand
Me.OleDbSelectC ommand2 = New System.Data.Ole Db.OleDbCommand
Me.OleDbUpdateC ommand2 = New System.Data.Ole Db.OleDbCommand
Me.Label1 = New System.Windows. Forms.Label
Me.Label2 = New System.Windows. Forms.Label
Me.Label3 = New System.Windows. Forms.Label
Me.Button1 = New System.Windows. Forms.Button
CType(Me.Ds1, System.Componen tModel.ISupport Initialize).Beg inInit()
CType(Me.DataGr id1,
System.Componen tModel.ISupport Initialize).Beg inInit()
Me.SuspendLayou t()
'
'OleDb
'
Me.OleDb.Delete Command = Me.OleDbDeleteC ommand1
Me.OleDb.Insert Command = Me.OleDbInsertC ommand1
Me.OleDb.Select Command = Me.OleDbSelectC ommand1
Me.OleDb.TableM appings.AddRang e(New
System.Data.Com mon.DataTableMa pping() {New
System.Data.Com mon.DataTableMa pping("Table", "rooms", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("id", "id"), New
System.Data.Com mon.DataColumnM apping("jobno", "jobno"), New
System.Data.Com mon.DataColumnM apping("roomdes c", "roomdesc") , New
System.Data.Com mon.DataColumnM apping("roomno" , "roomno")}) })
Me.OleDb.Update Command = Me.OleDbUpdateC ommand1
'
'OleDbDeleteCom mand1
'
Me.OleDbDeleteC ommand1.Command Text = "DELETE FROM rooms WHERE (id =
?) AND (jobno = ? OR ? IS NULL AND jobno IS NULL) A" & _
"ND (roomdesc = ? OR ? IS NULL AND roomdesc IS NULL) AND (roomno = ?
OR ? IS NULL" & _
" AND roomno IS NULL)"
Me.OleDbDeleteC ommand1.Connect ion = Me.OleDbConnect ion1
Me.OleDbDeleteC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_id ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"id", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_jo bno",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_jo bno1",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ro omdesc",
System.Data.Ole Db.OleDbType.Va rWChar, 250,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"roomdesc", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ro omdesc1",
System.Data.Ole Db.OleDbType.Va rWChar, 250,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"roomdesc", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ro omno",
System.Data.Ole Db.OleDbType.Va rWChar, 150,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"roomno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ro omno1",
System.Data.Ole Db.OleDbType.Va rWChar, 150,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"roomno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
'
'OleDbConnectio n1
'
Me.OleDbConnect ion1.Connection String = "Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data
Source=""C:\Doc uments and Setting" & _
"s\sfarmer\ My Documents\Visua l Studio
Projects2003\Pu nch\Punch.mdb"" ;Password=;Jet" & _
" OLEDB:Engine Type=5;Jet OLEDB:Global Bulk
Transactions=1; Provider=""Micr osoft.Je" & _
"t.OLEDB.4.0""; Jet OLEDB:System database=;Jet
OLEDB:SFP=False ;Extended Properties=" & _
";Mode=Shar e Deny None;Jet OLEDB:New Database Password=;Jet
OLEDB:Create System D" & _
"atabase=False; Jet OLEDB:Don't Copy Locale on Compact=False;J et
OLEDB:Compact Wit" & _
"hout Replica Repair=False;Us er ID=Admin;Jet OLEDB:Encrypt
Database=False"
'
'OleDbInsertCom mand1
'
Me.OleDbInsertC ommand1.Command Text = "INSERT INTO rooms(jobno,
roomdesc, roomno) VALUES (?, ?, ?)"
Me.OleDbInsertC ommand1.Connect ion = Me.OleDbConnect ion1
Me.OleDbInsertC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("jobno",
System.Data.Ole Db.OleDbType.In teger, 0, "jobno"))
Me.OleDbInsertC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("roomdesc",
System.Data.Ole Db.OleDbType.Va rWChar, 250, "roomdesc") )
Me.OleDbInsertC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("roomno",
System.Data.Ole Db.OleDbType.Va rWChar, 150, "roomno"))
'
'OleDbSelectCom mand1
'
Me.OleDbSelectC ommand1.Command Text = "SELECT id, jobno, roomdesc,
roomno FROM rooms"
Me.OleDbSelectC ommand1.Connect ion = Me.OleDbConnect ion1
'
'OleDbUpdateCom mand1
'
Me.OleDbUpdateC ommand1.Command Text = "UPDATE rooms SET jobno = ?,
roomdesc = ?, roomno = ? WHERE (id = ?) AND (jobno = " & _
"? OR ? IS NULL AND jobno IS NULL) AND (roomdesc = ? OR ? IS NULL
AND roomdesc IS" & _
" NULL) AND (roomno = ? OR ? IS NULL AND roomno IS NULL)"
Me.OleDbUpdateC ommand1.Connect ion = Me.OleDbConnect ion1
Me.OleDbUpdateC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("jobno",
System.Data.Ole Db.OleDbType.In teger, 0, "jobno"))
Me.OleDbUpdateC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("roomdesc",
System.Data.Ole Db.OleDbType.Va rWChar, 250, "roomdesc") )
Me.OleDbUpdateC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("roomno",
System.Data.Ole Db.OleDbType.Va rWChar, 150, "roomno"))
Me.OleDbUpdateC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_id ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"id", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_jo bno",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_jo bno1",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ro omdesc",
System.Data.Ole Db.OleDbType.Va rWChar, 250,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"roomdesc", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ro omdesc1",
System.Data.Ole Db.OleDbType.Va rWChar, 250,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"roomdesc", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ro omno",
System.Data.Ole Db.OleDbType.Va rWChar, 150,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"roomno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand1.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ro omno1",
System.Data.Ole Db.OleDbType.Va rWChar, 150,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"roomno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
'
'Ds1
'
Me.Ds1.DataSetN ame = "DS"
Me.Ds1.Locale = New System.Globaliz ation.CultureIn fo("en-US")
'
'DataGrid1
'
Me.DataGrid1.Da taMember = ""
Me.DataGrid1.He aderForeColor =
System.Drawing. SystemColors.Co ntrolText
Me.DataGrid1.Lo cation = New System.Drawing. Point(15, 11)
Me.DataGrid1.Na me = "DataGrid1"
Me.DataGrid1.Si ze = New System.Drawing. Size(822, 279)
Me.DataGrid1.Ta bIndex = 0
'
'OleDb2
'
Me.OleDb2.Delet eCommand = Me.OleDbDeleteC ommand2
Me.OleDb2.Inser tCommand = Me.OleDbInsertC ommand2
Me.OleDb2.Selec tCommand = Me.OleDbSelectC ommand2
Me.OleDb2.Table Mappings.AddRan ge(New
System.Data.Com mon.DataTableMa pping() {New
System.Data.Com mon.DataTableMa pping("Table", "Responsibl e", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("abbr", "abbr"), New
System.Data.Com mon.DataColumnM apping("id", "id"), New
System.Data.Com mon.DataColumnM apping("jobno", "jobno"), New
System.Data.Com mon.DataColumnM apping("resp", "resp")})})
Me.OleDb2.Updat eCommand = Me.OleDbUpdateC ommand2
'
'OleDbDeleteCom mand2
'
Me.OleDbDeleteC ommand2.Command Text = "DELETE FROM Responsible WHERE
(id = ?) AND (abbr = ? OR ? IS NULL AND abbr IS NUL" & _
"L) AND (jobno = ? OR ? IS NULL AND jobno IS NULL) AND (resp = ? OR
? IS NULL AND" & _
" resp IS NULL)"
Me.OleDbDeleteC ommand2.Connect ion = Me.OleDbConnect ion1
Me.OleDbDeleteC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_id ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"id", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ab br",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"abbr", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ab br1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"abbr", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_jo bno",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_jo bno1",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_re sp",
System.Data.Ole Db.OleDbType.Va rWChar, 150,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"resp", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbDeleteC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_re sp1",
System.Data.Ole Db.OleDbType.Va rWChar, 150,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"resp", System.Data.Dat aRowVersion.Ori ginal, Nothing))
'
'OleDbInsertCom mand2
'
Me.OleDbInsertC ommand2.Command Text = "INSERT INTO Responsible(abb r,
jobno, resp) VALUES (?, ?, ?)"
Me.OleDbInsertC ommand2.Connect ion = Me.OleDbConnect ion1
Me.OleDbInsertC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("abbr",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "abbr"))
Me.OleDbInsertC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("jobno",
System.Data.Ole Db.OleDbType.In teger, 0, "jobno"))
Me.OleDbInsertC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("resp",
System.Data.Ole Db.OleDbType.Va rWChar, 150, "resp"))
'
'OleDbSelectCom mand2
'
Me.OleDbSelectC ommand2.Command Text = "SELECT abbr, id, jobno, resp
FROM Responsible"
Me.OleDbSelectC ommand2.Connect ion = Me.OleDbConnect ion1
'
'OleDbUpdateCom mand2
'
Me.OleDbUpdateC ommand2.Command Text = "UPDATE Responsible SET abbr =
?, jobno = ?, resp = ? WHERE (id = ?) AND (abbr = ?" & _
" OR ? IS NULL AND abbr IS NULL) AND (jobno = ? OR ? IS NULL AND
jobno IS NULL) A" & _
"ND (resp = ? OR ? IS NULL AND resp IS NULL)"
Me.OleDbUpdateC ommand2.Connect ion = Me.OleDbConnect ion1
Me.OleDbUpdateC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("abbr",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "abbr"))
Me.OleDbUpdateC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("jobno",
System.Data.Ole Db.OleDbType.In teger, 0, "jobno"))
Me.OleDbUpdateC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("resp",
System.Data.Ole Db.OleDbType.Va rWChar, 150, "resp"))
Me.OleDbUpdateC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_id ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"id", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ab br",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"abbr", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_ab br1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"abbr", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_jo bno",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_jo bno1",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_re sp",
System.Data.Ole Db.OleDbType.Va rWChar, 150,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"resp", System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.OleDbUpdateC ommand2.Paramet ers.Add(New
System.Data.Ole Db.OleDbParamet er("Original_re sp1",
System.Data.Ole Db.OleDbType.Va rWChar, 150,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"resp", System.Data.Dat aRowVersion.Ori ginal, Nothing))
'
'Label1
'
Me.Label1.AutoS ize = True
Me.Label1.DataB indings.Add(New System.Windows. Forms.Binding(" Text",
Me.Ds1, "rooms.roomno") )
Me.Label1.Locat ion = New System.Drawing. Point(179, 319)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(38, 16)
Me.Label1.TabIn dex = 2
Me.Label1.Text = "Label1"
'
'Label2
'
Me.Label2.AutoS ize = True
Me.Label2.Locat ion = New System.Drawing. Point(180, 343)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing. Size(38, 16)
Me.Label2.TabIn dex = 3
Me.Label2.Text = "Label2"
'
'Label3
'
Me.Label3.AutoS ize = True
Me.Label3.Locat ion = New System.Drawing. Point(183, 368)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing. Size(38, 16)
Me.Label3.TabIn dex = 4
Me.Label3.Text = "Label3"
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(199, 477)
Me.Button1.Name = "Button1"
Me.Button1.TabI ndex = 5
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(886, 689)
Me.Controls.Add (Me.Button1)
Me.Controls.Add (Me.Label3)
Me.Controls.Add (Me.Label2)
Me.Controls.Add (Me.Label1)
Me.Controls.Add (Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.Ds1, System.Componen tModel.ISupport Initialize).End Init()
CType(Me.DataGr id1,
System.Componen tModel.ISupport Initialize).End Init()
Me.ResumeLayout (False)
End Sub
#End Region
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
OleDb.Fill(Ds1)
'------DataGrid1 TABLESTYLE----------------------
Dim ts As DataGridTableSt yle
DataGrid1.DataS ource = Ds1
DataGrid1.DataM ember = "rooms"
ts = New DataGridTableSt yle
ts.MappingName = "rooms"
ts.PreferredRow Height = 25
ts.AlternatingB ackColor = System.Drawing. Color.FromArgb( CType(252,
Byte), CType(253, Byte), CType(206, Byte))
ts.HeaderBackCo lor = System.Drawing. Color.FromArgb( 255, 252, 253,
206)
ts.HeaderForeCo lor = System.Drawing. Color.Black
'-------dg_punch COLUMNSTYLES----------------------
Dim tb1 As DataGridTextBox Column
tb1 = New DataGridTextBox Column
tb1.HeaderText = "Room Number"
tb1.MappingName = "roomno"
tb1.NullText = ""
tb1.Width = 150
ts.GridColumnSt yles.Add(tb1)
Dim tb2 As DataGridTextBox Column
tb2 = New DataGridTextBox Column
tb2.HeaderText = "Room Description"
tb2.MappingName = "roomdesc"
tb2.NullText = ""
tb2.Width = 350
ts.GridColumnSt yles.Add(tb2)
DataGrid1.Table Styles.Add(ts)
End Sub
Private Sub Handle_CurrentC ellChanged(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles DataGrid1.Curre ntCellChanged
Dim roomvar As String =
Me.DataGrid1.It em(Me.DataGrid1 .CurrentRowInde x, 0).ToString
Dim DV As New DataView(Ds1.Ta bles("rooms"))
DV.RowFilter = "roomno like '" & roomvar & "'"
'If DV.Count > 0 Then
' MsgBox(Me.DataG rid1.Item(Me.Da taGrid1.Current RowIndex,
0).ToString)
' End If
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim roomvar As String =
Me.DataGrid1.It em(Me.DataGrid1 .CurrentRowInde x, 0).ToString
Dim DV As New DataView(Ds1.Ta bles("rooms"))
DV.Sort = "roomno"
' DV.RowFilter = "roomno like '" & roomvar & "'"
DV.RowFilter = "roomno like '001aa' "
Dim dr As DataRow
Label1.Text = Me.DataGrid1.It em(Me.DataGrid1 .CurrentRowInde x,
0).ToString
Label2.Text = DV.Count.ToStri ng
Label3.Text = DV.RowFilter.To String
' If DV.Count > 0 Then MsgBox("over")
MsgBox(Applicat ion.ProductVers ion.ToString)
End Sub
End Class
"Cor" <no*@non.com> wrote in message
news:uG******** ******@TK2MSFTN GP09.phx.gbl...
Hi Steve,
Correct me if I understand it wrong, but everything that is on your
datagrid1 is in your Ds1.tables("roo ms")
And now I am currious what cannot be in that dataset and from where you
get that data?
The dataset can of course have more columns, (I did not see your select
statement, not that I needed that)
If it is an access or an SQL database is not important for this.
Cor
Datagrid source is a Dataset (DS1)
Dataset source is an Access database.
Here is my DataGrid code if needed.
Thank you for your help.
'------DataGrid1 TABLESTYLE----------------------
Dim ts As DataGridTableSt yle
DataGrid1.DataS ource = Ds1
DataGrid1.DataM ember = "rooms"
ts = New DataGridTableSt yle
ts.MappingName = "rooms"
ts.PreferredRow Height = 25
ts.AlternatingB ackColor = System.Drawing. Color.FromArgb( CType(252,
Byte), CType(253, Byte), CType(206, Byte))
ts.HeaderBackCo lor = System.Drawing. Color.FromArgb( 255, 252, 253, 206)
ts.HeaderForeCo lor = System.Drawing. Color.Black
'-------dg_punch COLUMNSTYLES----------------------
Dim tb1 As DataGridTextBox Column
tb1 = New DataGridTextBox Column
tb1.HeaderText = "Room Number"
tb1.MappingName = "roomno"
tb1.NullText = ""
tb1.Width = 150
ts.GridColumnSt yles.Add(tb1)
Dim tb2 As DataGridTextBox Column
tb2 = New DataGridTextBox Column
tb2.HeaderText = "Room Description"
tb2.MappingName = "roomdesc"
tb2.NullText = ""
tb2.Width = 350
ts.GridColumnSt yles.Add(tb2)
DataGrid1.Table Styles.Add(ts)
"Cor" <no*@non.com> wrote in message
news:ON******** ******@TK2MSFTN GP09.phx.gbl... Hi Steve,
I have looked it then times over so a little question first.
>
> Here is the confusion...... ...
> I thought that the DataView is the view from the dataset, but it
seems that
> the dataview has the records that are in the datagrid, because
everytime I > search for a record that I know is NOT in the dataset, it finds it.
I don't
> get it.
>
What is the datasource from your datagrid?
And if it is a dataview what is the source of that dataview?
Cor