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.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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.OleDb.OleDbDataAdapter
Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbUpdateCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbDeleteCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
Friend WithEvents Ds1 As Datagrid_Test.DS
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents OleDb2 As System.Data.OleDb.OleDbDataAdapter
Friend WithEvents OleDbSelectCommand2 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbInsertCommand2 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbUpdateCommand2 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbDeleteCommand2 As System.Data.OleDb.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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.OleDb = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbDeleteCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbUpdateCommand1 = New System.Data.OleDb.OleDbCommand
Me.Ds1 = New Datagrid_Test.DS
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.OleDb2 = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbDeleteCommand2 = New System.Data.OleDb.OleDbCommand
Me.OleDbInsertCommand2 = New System.Data.OleDb.OleDbCommand
Me.OleDbSelectCommand2 = New System.Data.OleDb.OleDbCommand
Me.OleDbUpdateCommand2 = New System.Data.OleDb.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.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'OleDb
'
Me.OleDb.DeleteCommand = Me.OleDbDeleteCommand1
Me.OleDb.InsertCommand = Me.OleDbInsertCommand1
Me.OleDb.SelectCommand = Me.OleDbSelectCommand1
Me.OleDb.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "rooms", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("id", "id"), New
System.Data.Common.DataColumnMapping("jobno", "jobno"), New
System.Data.Common.DataColumnMapping("roomdesc", "roomdesc"), New
System.Data.Common.DataColumnMapping("roomno", "roomno")})})
Me.OleDb.UpdateCommand = Me.OleDbUpdateCommand1
'
'OleDbDeleteCommand1
'
Me.OleDbDeleteCommand1.CommandText = "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.OleDbDeleteCommand1.Connection = Me.OleDbConnection1
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_id",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"id", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_jobno",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_jobno1",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_roomdesc",
System.Data.OleDb.OleDbType.VarWChar, 250,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"roomdesc", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_roomdesc1",
System.Data.OleDb.OleDbType.VarWChar, 250,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"roomdesc", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_roomno",
System.Data.OleDb.OleDbType.VarWChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"roomno", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_roomno1",
System.Data.OleDb.OleDbType.VarWChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"roomno", System.Data.DataRowVersion.Original, Nothing))
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB
atabase L" & _
"ocking Mode=1;Jet OLEDB
atabase Password=;Data
Source=""C:\Documents and Setting" & _
"s\sfarmer\My Documents\Visual Studio
Projects2003\Punch\Punch.mdb"";Password=;Jet" & _
" OLEDB:Engine Type=5;Jet OLEDB:Global Bulk
Transactions=1;Provider=""Microsoft.Je" & _
"t.OLEDB.4.0"";Jet OLEDB:System database=;Jet
OLEDB:SFP=False;Extended Properties=" & _
";Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet
OLEDB:Create System D" & _
"atabase=False;Jet OLEDB
on't Copy Locale on Compact=False;Jet
OLEDB:Compact Wit" & _
"hout Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt
Database=False"
'
'OleDbInsertCommand1
'
Me.OleDbInsertCommand1.CommandText = "INSERT INTO rooms(jobno,
roomdesc, roomno) VALUES (?, ?, ?)"
Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("jobno",
System.Data.OleDb.OleDbType.Integer, 0, "jobno"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("roomdesc",
System.Data.OleDb.OleDbType.VarWChar, 250, "roomdesc"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("roomno",
System.Data.OleDb.OleDbType.VarWChar, 150, "roomno"))
'
'OleDbSelectCommand1
'
Me.OleDbSelectCommand1.CommandText = "SELECT id, jobno, roomdesc,
roomno FROM rooms"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
'
'OleDbUpdateCommand1
'
Me.OleDbUpdateCommand1.CommandText = "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.OleDbUpdateCommand1.Connection = Me.OleDbConnection1
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("jobno",
System.Data.OleDb.OleDbType.Integer, 0, "jobno"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("roomdesc",
System.Data.OleDb.OleDbType.VarWChar, 250, "roomdesc"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("roomno",
System.Data.OleDb.OleDbType.VarWChar, 150, "roomno"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_id",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"id", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_jobno",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_jobno1",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_roomdesc",
System.Data.OleDb.OleDbType.VarWChar, 250,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"roomdesc", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_roomdesc1",
System.Data.OleDb.OleDbType.VarWChar, 250,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"roomdesc", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_roomno",
System.Data.OleDb.OleDbType.VarWChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"roomno", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_roomno1",
System.Data.OleDb.OleDbType.VarWChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"roomno", System.Data.DataRowVersion.Original, Nothing))
'
'Ds1
'
Me.Ds1.DataSetName = "DS"
Me.Ds1.Locale = New System.Globalization.CultureInfo("en-US")
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor =
System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(15, 11)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(822, 279)
Me.DataGrid1.TabIndex = 0
'
'OleDb2
'
Me.OleDb2.DeleteCommand = Me.OleDbDeleteCommand2
Me.OleDb2.InsertCommand = Me.OleDbInsertCommand2
Me.OleDb2.SelectCommand = Me.OleDbSelectCommand2
Me.OleDb2.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "Responsible", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("abbr", "abbr"), New
System.Data.Common.DataColumnMapping("id", "id"), New
System.Data.Common.DataColumnMapping("jobno", "jobno"), New
System.Data.Common.DataColumnMapping("resp", "resp")})})
Me.OleDb2.UpdateCommand = Me.OleDbUpdateCommand2
'
'OleDbDeleteCommand2
'
Me.OleDbDeleteCommand2.CommandText = "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.OleDbDeleteCommand2.Connection = Me.OleDbConnection1
Me.OleDbDeleteCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_id",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"id", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_abbr",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"abbr", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_abbr1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"abbr", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_jobno",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_jobno1",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_resp",
System.Data.OleDb.OleDbType.VarWChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"resp", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_resp1",
System.Data.OleDb.OleDbType.VarWChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"resp", System.Data.DataRowVersion.Original, Nothing))
'
'OleDbInsertCommand2
'
Me.OleDbInsertCommand2.CommandText = "INSERT INTO Responsible(abbr,
jobno, resp) VALUES (?, ?, ?)"
Me.OleDbInsertCommand2.Connection = Me.OleDbConnection1
Me.OleDbInsertCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("abbr",
System.Data.OleDb.OleDbType.VarWChar, 50, "abbr"))
Me.OleDbInsertCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("jobno",
System.Data.OleDb.OleDbType.Integer, 0, "jobno"))
Me.OleDbInsertCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("resp",
System.Data.OleDb.OleDbType.VarWChar, 150, "resp"))
'
'OleDbSelectCommand2
'
Me.OleDbSelectCommand2.CommandText = "SELECT abbr, id, jobno, resp
FROM Responsible"
Me.OleDbSelectCommand2.Connection = Me.OleDbConnection1
'
'OleDbUpdateCommand2
'
Me.OleDbUpdateCommand2.CommandText = "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.OleDbUpdateCommand2.Connection = Me.OleDbConnection1
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("abbr",
System.Data.OleDb.OleDbType.VarWChar, 50, "abbr"))
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("jobno",
System.Data.OleDb.OleDbType.Integer, 0, "jobno"))
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("resp",
System.Data.OleDb.OleDbType.VarWChar, 150, "resp"))
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_id",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"id", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_abbr",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"abbr", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_abbr1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"abbr", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_jobno",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_jobno1",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"jobno", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_resp",
System.Data.OleDb.OleDbType.VarWChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"resp", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_resp1",
System.Data.OleDb.OleDbType.VarWChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"resp", System.Data.DataRowVersion.Original, Nothing))
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.DataBindings.Add(New System.Windows.Forms.Binding("Text",
Me.Ds1, "rooms.roomno"))
Me.Label1.Location = New System.Drawing.Point(179, 319)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(38, 16)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Label1"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(180, 343)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(38, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Label2"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(183, 368)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(38, 16)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Label3"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(199, 477)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 5
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = 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.ComponentModel.ISupportInitialize).EndInit()
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
OleDb.Fill(Ds1)
'------DataGrid1 TABLESTYLE----------------------
Dim ts As DataGridTableStyle
DataGrid1.DataSource = Ds1
DataGrid1.DataMember = "rooms"
ts = New DataGridTableStyle
ts.MappingName = "rooms"
ts.PreferredRowHeight = 25
ts.AlternatingBackColor = System.Drawing.Color.FromArgb(CType(252,
Byte), CType(253, Byte), CType(206, Byte))
ts.HeaderBackColor = System.Drawing.Color.FromArgb(255, 252, 253,
206)
ts.HeaderForeColor = System.Drawing.Color.Black
'-------dg_punch COLUMNSTYLES----------------------
Dim tb1 As DataGridTextBoxColumn
tb1 = New DataGridTextBoxColumn
tb1.HeaderText = "Room Number"
tb1.MappingName = "roomno"
tb1.NullText = ""
tb1.Width = 150
ts.GridColumnStyles.Add(tb1)
Dim tb2 As DataGridTextBoxColumn
tb2 = New DataGridTextBoxColumn
tb2.HeaderText = "Room Description"
tb2.MappingName = "roomdesc"
tb2.NullText = ""
tb2.Width = 350
ts.GridColumnStyles.Add(tb2)
DataGrid1.TableStyles.Add(ts)
End Sub
Private Sub Handle_CurrentCellChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.CurrentCellChanged
Dim roomvar As String =
Me.DataGrid1.Item(Me.DataGrid1.CurrentRowIndex, 0).ToString
Dim DV As New DataView(Ds1.Tables("rooms"))
DV.RowFilter = "roomno like '" & roomvar & "'"
'If DV.Count > 0 Then
' MsgBox(Me.DataGrid1.Item(Me.DataGrid1.CurrentRowIndex,
0).ToString)
' End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim roomvar As String =
Me.DataGrid1.Item(Me.DataGrid1.CurrentRowIndex, 0).ToString
Dim DV As New DataView(Ds1.Tables("rooms"))
DV.Sort = "roomno"
' DV.RowFilter = "roomno like '" & roomvar & "'"
DV.RowFilter = "roomno like '001aa' "
Dim dr As DataRow
Label1.Text = Me.DataGrid1.Item(Me.DataGrid1.CurrentRowIndex,
0).ToString
Label2.Text = DV.Count.ToString
Label3.Text = DV.RowFilter.ToString
' If DV.Count > 0 Then MsgBox("over")
MsgBox(Application.ProductVersion.ToString)
End Sub
End Class