By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,221 Members | 1,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,221 IT Pros & Developers. It's quick & easy.

DataView confusion

P: n/a
I have a form with a dataset and a datagrid.
I created a dataview on this dataset.
When the user modifies the datagrid, I look up this record in the dataview
to make sure it is unique.

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.

Is there a better way to find a record in a dataset? Here is the code I use.

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 & "'"
Dim dr As DataRow

'Used to debug................
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")
End Sub
Nov 20 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Cor
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
Nov 20 '05 #2

P: n/a
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 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)

"Cor" <no*@non.com> wrote in message
news:ON**************@TK2MSFTNGP09.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

Nov 20 '05 #3

P: n/a
Cor
Hi Steve,

Correct me if I understand it wrong, but everything that is on your
datagrid1 is in your Ds1.tables("rooms")

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 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)

"Cor" <no*@non.com> wrote in message
news:ON**************@TK2MSFTNGP09.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


Nov 20 '05 #4

P: n/a
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).BeginIni t()
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).BeginIni t()
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_roomdes c",
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_roomdes c1",
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:Database L" & _
"ocking Mode=1;Jet OLEDB:Database 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:Don'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_roomdes c",
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_roomdes c1",
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.CurrentRowIn dex,
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



"Cor" <no*@non.com> wrote in message
news:uG**************@TK2MSFTNGP09.phx.gbl...
Hi Steve,

Correct me if I understand it wrong, but everything that is on your
datagrid1 is in your Ds1.tables("rooms")

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 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)

"Cor" <no*@non.com> wrote in message
news:ON**************@TK2MSFTNGP09.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



Nov 20 '05 #5

P: n/a
Steve,
When I try your code with the titles table in the pubs database (sample DB
in SQL Server) I get a single row, as I would expect.
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. The DataGrid itself binds to a DataView not the DataTable per se, when you
assign a DataTable to the DataGrid.DataSource property. The DataGrid uses
the DataTable.DefaultView property to get a DataView object. A DataView is a
view (not a copy) of the data in the DataTable itself, so when you modify
data in the DataGrid this is reflected in the DataTable itself. Hence when
you create a second DataView over the DataTable, this second view also
reflects what is currently in the grid. Because the DataView is a view of
the data in a DataTable you can rather efficiently create multiple views of
the DataTable will consuming a lot of memory resources.

In other words the DataGrid & your DataView are both looking at the same
data in the DataTable itself. Neither made a copy of this data.

If you want to ensure that the column is unique, I would add a
UniqueConstraint to Ds1.Tables("rooms") for roomno. The DataTable itself
will then take care of it for you!.

If you don't have it, you may want to get David Sceppa's "Microsoft
ADO.NET - Core Reference" from MS Press as it is a good tutorial on ADO.NET
plus a good desk reference once you know ADO.NET!

Hope this helps
Jay

"Steve" <sf*****@flintind-remove.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... I have a form with a dataset and a datagrid.
I created a dataview on this dataset.
When the user modifies the datagrid, I look up this record in the dataview
to make sure it is unique.

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.

Is there a better way to find a record in a dataset? Here is the code I use.
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 & "'"
Dim dr As DataRow

'Used to debug................
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")
End Sub

Nov 20 '05 #6

P: n/a
Cor
Hi Steve,

I did look at your code, but you use it on a way that I think it is not made
for.

I will try to explain with a pseudo example.
We have a datatable that is a part of a dataset, we name it tbl1
It has 2 columns named "A" and "B" and only filled with
1 A
2 B
9 C
We make 2 datagrids

We read the table in our dataset

Then we make 2 dataviews of that table
dim dv1 as dataview(ds.table("tbl1"))
dim dv1 as dataview(ds.table("tbl1"))

We say
dv1.sort = "A Desc"
dv2.rowfilter = "A<5"

and we add them to the datagrids
datagrid1.datasource = dv1
datagrid2.datasource = dv2

And then it is shown.
Datagrid 1 has all rows and it goes
9 C
2 B
1 A
Datagrid 2 has
1 A
2 B

Now you change in datagrid 1 the 9 in a 0
You will see it shown up at the end of datagrid 2 and datagrid1 is
reordered.
(after you dit push on the column in front)

You enter a new row with a number 4 in datagrid 2
It will show up in datagrid 1.

The dataview is just a filter about the horizontaal rows as are the
colomnstyle for the columns.

All what you see in the datagrid is in the ds.tables("tbl1")

(Before you update it withouth changing a row you have to do endedit before
that)

I hope this makes it more clear.

Cor
Nov 20 '05 #7

P: n/a
Thank you Jay, I will look into getting this book. I guess I was thinking to
complicated.

Cor, I really appreciate you trying to explain this to me, but I am fairly
new with VB.NET, and after reading your last post, I was really confused and
still feel a little dizzy.

I guess I have do a whole lot more reading to understand this language.
Thank you everybody for your prompt help.

Steve

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eD**************@tk2msftngp13.phx.gbl...
Steve,
When I try your code with the titles table in the pubs database (sample DB
in SQL Server) I get a single row, as I would expect.
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.

The DataGrid itself binds to a DataView not the DataTable per se, when you
assign a DataTable to the DataGrid.DataSource property. The DataGrid uses
the DataTable.DefaultView property to get a DataView object. A DataView is

a view (not a copy) of the data in the DataTable itself, so when you modify
data in the DataGrid this is reflected in the DataTable itself. Hence when
you create a second DataView over the DataTable, this second view also
reflects what is currently in the grid. Because the DataView is a view of
the data in a DataTable you can rather efficiently create multiple views of the DataTable will consuming a lot of memory resources.

In other words the DataGrid & your DataView are both looking at the same
data in the DataTable itself. Neither made a copy of this data.

If you want to ensure that the column is unique, I would add a
UniqueConstraint to Ds1.Tables("rooms") for roomno. The DataTable itself
will then take care of it for you!.

If you don't have it, you may want to get David Sceppa's "Microsoft
ADO.NET - Core Reference" from MS Press as it is a good tutorial on ADO.NET plus a good desk reference once you know ADO.NET!

Hope this helps
Jay

"Steve" <sf*****@flintind-remove.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a form with a dataset and a datagrid.
I created a dataview on this dataset.
When the user modifies the datagrid, I look up this record in the dataview to make sure it is unique.

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.

Is there a better way to find a record in a dataset? Here is the code I

use.

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 & "'"
Dim dr As DataRow

'Used to debug................
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")
End Sub


Nov 20 '05 #8

P: n/a
Doh!
reflects what is currently in the grid. Because the DataView is a view of
the data in a DataTable you can rather efficiently create multiple views of the DataTable will consuming a lot of memory resources.
That last line should be:
the DataTable without consuming a lot of memory resources.

Jay

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eD**************@tk2msftngp13.phx.gbl... Steve,
When I try your code with the titles table in the pubs database (sample DB
in SQL Server) I get a single row, as I would expect.
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.

The DataGrid itself binds to a DataView not the DataTable per se, when you
assign a DataTable to the DataGrid.DataSource property. The DataGrid uses
the DataTable.DefaultView property to get a DataView object. A DataView is

a view (not a copy) of the data in the DataTable itself, so when you modify
data in the DataGrid this is reflected in the DataTable itself. Hence when
you create a second DataView over the DataTable, this second view also
reflects what is currently in the grid. Because the DataView is a view of
the data in a DataTable you can rather efficiently create multiple views of the DataTable will consuming a lot of memory resources.

In other words the DataGrid & your DataView are both looking at the same
data in the DataTable itself. Neither made a copy of this data.

If you want to ensure that the column is unique, I would add a
UniqueConstraint to Ds1.Tables("rooms") for roomno. The DataTable itself
will then take care of it for you!.

If you don't have it, you may want to get David Sceppa's "Microsoft
ADO.NET - Core Reference" from MS Press as it is a good tutorial on ADO.NET plus a good desk reference once you know ADO.NET!

Hope this helps
Jay

"Steve" <sf*****@flintind-remove.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a form with a dataset and a datagrid.
I created a dataview on this dataset.
When the user modifies the datagrid, I look up this record in the dataview to make sure it is unique.

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.

Is there a better way to find a record in a dataset? Here is the code I

use.

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 & "'"
Dim dr As DataRow

'Used to debug................
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")
End Sub


Nov 20 '05 #9

P: n/a
Cor
Hi Jay,

Do you believe I have 5 times readed that line and did not understand it, my
brainspellchecker did not work also.

:-))

Cor
the DataTable without consuming a lot of memory resources.

Nov 20 '05 #10

P: n/a
Jay,

my head is spinning.............

After I create the UniqueConstraint, do I set the DataSource for my DataGrid
to the DataTable (DT)?
Is that the best way to make sure the user does NOT modify the data to
something that is already there?

Here is my code so far........ but now what? Don't I need to catch that
somehow if there is a dup? Ahhhhhhhh!

Dim DT As DataTable = Ds1.Tables("rooms")
Dim UC As UniqueConstraint
Dim DC As DataColumn
DC = DT.Columns("roomno")
UC = New UniqueConstraint(DC)
DT.Constraints.Add(UC)
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eD**************@tk2msftngp13.phx.gbl...
Steve,
When I try your code with the titles table in the pubs database (sample DB
in SQL Server) I get a single row, as I would expect.
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.

The DataGrid itself binds to a DataView not the DataTable per se, when you
assign a DataTable to the DataGrid.DataSource property. The DataGrid uses
the DataTable.DefaultView property to get a DataView object. A DataView is

a view (not a copy) of the data in the DataTable itself, so when you modify
data in the DataGrid this is reflected in the DataTable itself. Hence when
you create a second DataView over the DataTable, this second view also
reflects what is currently in the grid. Because the DataView is a view of
the data in a DataTable you can rather efficiently create multiple views of the DataTable will consuming a lot of memory resources.

In other words the DataGrid & your DataView are both looking at the same
data in the DataTable itself. Neither made a copy of this data.

If you want to ensure that the column is unique, I would add a
UniqueConstraint to Ds1.Tables("rooms") for roomno. The DataTable itself
will then take care of it for you!.

If you don't have it, you may want to get David Sceppa's "Microsoft
ADO.NET - Core Reference" from MS Press as it is a good tutorial on ADO.NET plus a good desk reference once you know ADO.NET!

Hope this helps
Jay

"Steve" <sf*****@flintind-remove.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a form with a dataset and a datagrid.
I created a dataview on this dataset.
When the user modifies the datagrid, I look up this record in the dataview to make sure it is unique.

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.

Is there a better way to find a record in a dataset? Here is the code I

use.

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 & "'"
Dim dr As DataRow

'Used to debug................
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")
End Sub


Nov 20 '05 #11

P: n/a
Steve,
After I create the UniqueConstraint, do I set the DataSource for my DataGrid to the DataTable (DT)? You set the DataGrid.DataSource to the DataTable in the same way you
currently are:
Is that the best way to make sure the user does NOT modify the data to
something that is already there? Its the "easiest" way.
Don't I need to catch that
somehow if there is a dup? Ahhhhhhhh! Why do you need to catch it? The DataGrid itself will let the user know
there is a duplicate and ask if they want to correct it or not.
Here is my code so far........ but now what? Your code will work as is, now set the DataGrid.DataSource to
Ds1.Tables("rooms") the DataGrid will take care of every thing else for you!

Don't Worry, Be Happy, and Run your program! ;-)

If you want "finer" control over it, a different dialog box for example, you
could handle the DataTable.ColumnChanging event to see what the new value
might be and act accordingly. However that is probably more work then you
really need...

Hope this helps
Jay
"Steve" <sf*****@flintind-remove.com> wrote in message
news:Of**************@TK2MSFTNGP12.phx.gbl... Jay,

my head is spinning.............

After I create the UniqueConstraint, do I set the DataSource for my DataGrid to the DataTable (DT)?
Is that the best way to make sure the user does NOT modify the data to
something that is already there?

Here is my code so far........ but now what? Don't I need to catch that
somehow if there is a dup? Ahhhhhhhh!

Dim DT As DataTable = Ds1.Tables("rooms")
Dim UC As UniqueConstraint
Dim DC As DataColumn
DC = DT.Columns("roomno")
UC = New UniqueConstraint(DC)
DT.Constraints.Add(UC)
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eD**************@tk2msftngp13.phx.gbl...
Steve,
When I try your code with the titles table in the pubs database (sample DB
in SQL Server) I get a single row, as I would expect.
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.

The DataGrid itself binds to a DataView not the DataTable per se, when you assign a DataTable to the DataGrid.DataSource property. The DataGrid uses the DataTable.DefaultView property to get a DataView object. A DataView is a
view (not a copy) of the data in the DataTable itself, so when you
modify data in the DataGrid this is reflected in the DataTable itself. Hence when you create a second DataView over the DataTable, this second view also
reflects what is currently in the grid. Because the DataView is a view of the data in a DataTable you can rather efficiently create multiple views

of
the DataTable will consuming a lot of memory resources.

In other words the DataGrid & your DataView are both looking at the same
data in the DataTable itself. Neither made a copy of this data.

If you want to ensure that the column is unique, I would add a
UniqueConstraint to Ds1.Tables("rooms") for roomno. The DataTable itself
will then take care of it for you!.

If you don't have it, you may want to get David Sceppa's "Microsoft
ADO.NET - Core Reference" from MS Press as it is a good tutorial on

ADO.NET
plus a good desk reference once you know ADO.NET!

Hope this helps
Jay

"Steve" <sf*****@flintind-remove.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a form with a dataset and a datagrid.
I created a dataview on this dataset.
When the user modifies the datagrid, I look up this record in the dataview to make sure it is unique.

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.

Is there a better way to find a record in a dataset? Here is the code

I use.

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 & "'"
Dim dr As DataRow

'Used to debug................
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")
End Sub



Nov 20 '05 #12

P: n/a
Jay,

you're right, that works great. Is there a way to modify the default msgbox
text that is displayed? My users are non-technical, and they don't care
about the unique stuff.............

Thank you for all your help!!

Steve

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ew**************@TK2MSFTNGP12.phx.gbl...
Steve,
After I create the UniqueConstraint, do I set the DataSource for my DataGrid
to the DataTable (DT)?

You set the DataGrid.DataSource to the DataTable in the same way you
currently are:
Is that the best way to make sure the user does NOT modify the data to
something that is already there?

Its the "easiest" way.
Don't I need to catch that
somehow if there is a dup? Ahhhhhhhh!

Why do you need to catch it? The DataGrid itself will let the user know
there is a duplicate and ask if they want to correct it or not.
Here is my code so far........ but now what?

Your code will work as is, now set the DataGrid.DataSource to
Ds1.Tables("rooms") the DataGrid will take care of every thing else for

you!
Don't Worry, Be Happy, and Run your program! ;-)

If you want "finer" control over it, a different dialog box for example, you could handle the DataTable.ColumnChanging event to see what the new value
might be and act accordingly. However that is probably more work then you
really need...

Hope this helps
Jay
"Steve" <sf*****@flintind-remove.com> wrote in message
news:Of**************@TK2MSFTNGP12.phx.gbl...
Jay,

my head is spinning.............

After I create the UniqueConstraint, do I set the DataSource for my DataGrid
to the DataTable (DT)?
Is that the best way to make sure the user does NOT modify the data to
something that is already there?

Here is my code so far........ but now what? Don't I need to catch that
somehow if there is a dup? Ahhhhhhhh!

Dim DT As DataTable = Ds1.Tables("rooms")
Dim UC As UniqueConstraint
Dim DC As DataColumn
DC = DT.Columns("roomno")
UC = New UniqueConstraint(DC)
DT.Constraints.Add(UC)
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eD**************@tk2msftngp13.phx.gbl...
Steve,
When I try your code with the titles table in the pubs database (sample DB in SQL Server) I get a single row, as I would expect.

> 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.
The DataGrid itself binds to a DataView not the DataTable per se, when
you assign a DataTable to the DataGrid.DataSource property. The DataGrid uses the DataTable.DefaultView property to get a DataView object. A DataView is
a
view (not a copy) of the data in the DataTable itself, so when you modify data in the DataGrid this is reflected in the DataTable itself. Hence when you create a second DataView over the DataTable, this second view also
reflects what is currently in the grid. Because the DataView is a view of the data in a DataTable you can rather efficiently create multiple
views of
the DataTable will consuming a lot of memory resources.

In other words the DataGrid & your DataView are both looking at the
same data in the DataTable itself. Neither made a copy of this data.

If you want to ensure that the column is unique, I would add a
UniqueConstraint to Ds1.Tables("rooms") for roomno. The DataTable itself will then take care of it for you!.

If you don't have it, you may want to get David Sceppa's "Microsoft
ADO.NET - Core Reference" from MS Press as it is a good tutorial on

ADO.NET
plus a good desk reference once you know ADO.NET!

Hope this helps
Jay

"Steve" <sf*****@flintind-remove.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> I have a form with a dataset and a datagrid.
> I created a dataview on this dataset.
> When the user modifies the datagrid, I look up this record in the

dataview
> to make sure it is unique.
>
> 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.
>
> Is there a better way to find a record in a dataset? Here is the code I use.
>
> 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 & "'"
> Dim dr As DataRow
>
> 'Used to debug................
> 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")
>
>
> End Sub
>
>



Nov 20 '05 #13

P: n/a
Steve,
If you want to change the "default MessageBox", I would look at handling the
DataTable.ColumnChanging event as I suggested, however I do not have a
sample of that.

Hope this helps
Jay
"Steve" <sf*****@flintind-remove.com> wrote in message
news:eQ**************@TK2MSFTNGP11.phx.gbl...
Jay,

you're right, that works great. Is there a way to modify the default msgbox text that is displayed? My users are non-technical, and they don't care
about the unique stuff.............

Thank you for all your help!!

Steve

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ew**************@TK2MSFTNGP12.phx.gbl...
Steve,
After I create the UniqueConstraint, do I set the DataSource for my DataGrid
to the DataTable (DT)?

You set the DataGrid.DataSource to the DataTable in the same way you
currently are:
Is that the best way to make sure the user does NOT modify the data to
something that is already there?

Its the "easiest" way.
Don't I need to catch that
somehow if there is a dup? Ahhhhhhhh!

Why do you need to catch it? The DataGrid itself will let the user know
there is a duplicate and ask if they want to correct it or not.
Here is my code so far........ but now what?

Your code will work as is, now set the DataGrid.DataSource to
Ds1.Tables("rooms") the DataGrid will take care of every thing else for

you!

Don't Worry, Be Happy, and Run your program! ;-)

If you want "finer" control over it, a different dialog box for example,

you
could handle the DataTable.ColumnChanging event to see what the new value
might be and act accordingly. However that is probably more work then you really need...

Hope this helps
Jay
"Steve" <sf*****@flintind-remove.com> wrote in message
news:Of**************@TK2MSFTNGP12.phx.gbl...
Jay,

my head is spinning.............

After I create the UniqueConstraint, do I set the DataSource for my

DataGrid
to the DataTable (DT)?
Is that the best way to make sure the user does NOT modify the data to
something that is already there?

Here is my code so far........ but now what? Don't I need to catch that somehow if there is a dup? Ahhhhhhhh!

Dim DT As DataTable = Ds1.Tables("rooms")
Dim UC As UniqueConstraint
Dim DC As DataColumn
DC = DT.Columns("roomno")
UC = New UniqueConstraint(DC)
DT.Constraints.Add(UC)
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:eD**************@tk2msftngp13.phx.gbl...
> Steve,
> When I try your code with the titles table in the pubs database (sample
DB
> in SQL Server) I get a single row, as I would expect.
>
> > 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.
> The DataGrid itself binds to a DataView not the DataTable per se,
when you
> assign a DataTable to the DataGrid.DataSource property. The DataGrid uses
> the DataTable.DefaultView property to get a DataView object. A DataView
is
a
> view (not a copy) of the data in the DataTable itself, so when you

modify
> data in the DataGrid this is reflected in the DataTable itself.

Hence when
> you create a second DataView over the DataTable, this second view
also > reflects what is currently in the grid. Because the DataView is a view of
> the data in a DataTable you can rather efficiently create multiple

views of
> the DataTable will consuming a lot of memory resources.
>
> In other words the DataGrid & your DataView are both looking at the same > data in the DataTable itself. Neither made a copy of this data.
>
> If you want to ensure that the column is unique, I would add a
> UniqueConstraint to Ds1.Tables("rooms") for roomno. The DataTable itself > will then take care of it for you!.
>
> If you don't have it, you may want to get David Sceppa's "Microsoft
> ADO.NET - Core Reference" from MS Press as it is a good tutorial on
ADO.NET
> plus a good desk reference once you know ADO.NET!
>
> Hope this helps
> Jay
>
> "Steve" <sf*****@flintind-remove.com> wrote in message
> news:%2****************@tk2msftngp13.phx.gbl...
> > I have a form with a dataset and a datagrid.
> > I created a dataview on this dataset.
> > When the user modifies the datagrid, I look up this record in the
dataview
> > to make sure it is unique.
> >
> > 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.
> >
> > Is there a better way to find a record in a dataset? Here is the code
I
> use.
> >
> > 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 & "'"
> > Dim dr As DataRow
> >
> > 'Used to debug................
> > 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")
> >
> >
> > End Sub
> >
> >
>
>



Nov 20 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.