SlideShare a Scribd company logo
VB .NET Database Access
Microsoft Universal Data Access 
• ODBC: Open Database Connectivity 
– A driver manager 
– Used for relational databases 
• OLE DB: The OLE database protocol 
– Allows a program to access information in many types 
of data source. 
– Data provider: databases, spreadsheets, etc. 
• ADO.NET: ActiveX Data Objects 
– An Interface for OLE DB. 
– Allow programmers to use a standard set of objects to 
refer to any OLE DB data source.
.Net Applications 
OLE DB 
Provider 
OLE DB 
Data Source 
ADO.Net 
OLE DB 
Provider 
ODBC 
ODBC 
Data Source 
SQL Server 
.Net Data Provider 
SQL Server 
Data Source 
OLE DB 
.Net Data Provider
Using ODBC 
• Windows 2000/2003: 
• Control Panel /Administrative Tools/DataSource(ODBC) 
• Three types of data source names 
– User DSN: usable only by you and only on the machine 
currently using. 
– System DSN: Any one using the machine can use. 
– File DSN: Can be copied and used by other computers 
with the same driver installed.
VB.NET Database Tools 
• Database connection: 
– Tool/Connect to database 
• Provider:MS Jet 4.0 OLE DB Provider 
• Connection 
• Server Explorer 
– Data connections: 
• Right click and Add Connection 
• Tables, Views 
• Toolbox:Data tab 
• Data Form Wizard
Steps to Retrieve Data 
• Establishes a connection to the database. 
• Executes commands against the database. 
• Store data results.
ADO.NET Objects 
.NET Applications 
Data Set 
Data Reader 
Adapter 
Command Object 
Connection Object 
Database
ADO.NET Objects 
• Connection Object: Represent a connection to the 
database. 
• Command Object: The command object allows us 
to execute a SQL statement or a stored procedure. 
• DataReader: It is a read-only and forward-only 
pointer into a table to retrieve records. 
• DataSet Object: A DataSet object can hold several 
tables and relationships between tables. 
• DataAdapter: This the object used to pass data 
between the database and the dataset.
How to create an ADO.Net object? 
• Using Wizard 
– Data Form Wizard 
– Data Adapter Wizard 
• Using code: 
– Example: 
– dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = 
c:sales2k.mdb" 
– dim objConn as new OledbConnection(strConn) 
– objConn.open()
Data Form Wizard 
• Creating a form with ADO.Net objects and data-bound 
controls to display and update information 
in a dataset. 
• Demo: Using Data Form Wizard to create a 
navigational form. 
– Project/Add Windows Form/Data Form Wizard 
– Set connection 
– Choose tables 
– Display records in grid or in text boxes.
Adapter & Dataset Context Menu 
• Adapter: 
– Properties: 
• Command objects 
– Configure Adapter 
– Generate dataset 
– Preview data 
• Dataset: 
– View Schema: Dataset/XML
Other Data Form Demos 
• Display records in text boxes. 
• Add /Modify/Delete records. 
• Hierarchical forms: 
– Parent/Child relationship
Creating A Database Application 
Without Programming 
• Creating a database application to display 
information and update database. 
• A main form with buttons to open data 
forms: 
– DisplayInfo 
– Enter New 
– Modify 
– Exit
Data Adapter Wizard 
• Configure Data Adapter and generating a 
dataset: 
– Drag OledbDataAdapter (or database’s table) to 
the form. 
– Use the Data Adapter Wizard to configure the 
Adapter. 
– Right Click the Adapter to preview data and 
creating dataset. 
• Bind the dataset to controls.
Data Binding 
• Connect a control or property to one or more data 
elements. 
• Simple binding: Use simple binding to display a 
field value in controls that show Data Bindings in 
the property window, such as text box or label. 
• Complex binding: Use complex binding to bind 
more than one field to controls such as DataGrid 
and list box. Use the control’s Data Source and 
Data Member to bind the data.
Creating Bound Controls 
• DataGrid control: 
– Data Source property 
– Data Member property 
– In the Form Load event, use Adapter’s Fill 
method to load the dataset: 
• OleDbDataAdapter1.Fill(DataSet11)
Binding Text Box 
• Data Bindings property: 
– Text: choose field 
• Add navigation buttons: 
– The current record position within the dataset is 
stored in a form’s BindingContext’s Position 
property. This position is zero based. Add one 
move to the next record, minus one move to the 
previous record.
MoveNext and MoveLast Example 
• MoveNext: 
– Me.BindingContext(DataSet21, "customer").Position += 1 
• MoveLast: 
– Me.BindingContext(DataSet21, "customer").Position = 
Me.BindingContext(DataSet21, "customer").Count -1 
• How to MovePrevious and MoveFirst? 
• Note: The Position property takes care of the end of file 
automatically.
CurrencyManager 
• Dim custCurrMgr As CurrencyManager 
• Dim ordCurrMgr As CurrencyManager 
• In a procedure: 
– ordCurrMgr = Me.BindingContext(Ds31, "orders") 
– custCurrMgr = Me.BindingContext(Ds31, “customer") 
– custCurrMgr.Position += 1 
– ordCurrMgr.Position += 1
Binding DataGrid 
• From Server Explorer, drag the table from a 
database connection (or from Data tab, drag 
a oleDbAdapter) onto the form. 
• Create dataset. 
• Drag DataGrid and set the DataSource and 
Data Member property. 
• Use adapter’s Fill method to load the 
dataset.
Displaying Many Tables with 
One DataGrid 
• Define one Adapter for each table. 
• Create the dataset with multiple tables. 
• Add a DataGrid control and set the 
DataSource proeprty to the dataset name 
and leave the DataMember property blank.
Creating Hierarchical Data Grid 
• Define two Adapters, one for the parent table and 
one for the child table. 
• Create the dataset. 
• Right-click the dataset to View Schema 
• Right-click the parent table and choose Add/New 
Relation 
• Add a DataGrid control and set the DataSource 
proeprty to the dataset.parentTable and leave the 
DataMember property blank. 
• Note: DO File/SaveAll after creating the relation.
Binding ListBox 
• Example: Bind Customer Table’s CID field to a 
listbox. 
– Create a Adapter to retrieve CID (and Cname) fields , 
and generate the dataset. 
– Add ListBox and set binding properties: 
• Data Source 
• Display Member 
• Value Member: the actual values for items in the list box. To 
display the selected item’s value in a text box, do: 
– Textbox1.text = ListBox1.SelectedValue 
• Can we use TextBox1.text=ListBox1.SelectedItem? 
No!
Display Selected Record 
• Bound textbox: 
– Me.BindingContext(DataSet11, 
"customer").Position = ListBox1.SelectedIndex 
– 
• Unbound textbox
ListBox SelectedItem Property 
• How to display the selected record in unbound 
textbox? 
• After binding to a data source, this property return a 
DataRowView object. 
• What is DataRowView? 
– Object Browser: 
• System.Data 
– System.Data 
» DataRowView: Item property 
• To retrieve a column from a DataRowView object 
(use 0-based index to identity a column): 
• ListBox1.SelectedItem.Item(1) 
• Or: ListBox1.SelectedItem(1) 
• Or: ListBox1.SelectedItem(“Cname”)
Using Object Browser 
• View/Object Browser 
• DataSet object model: 
• System.Data 
– DataSet 
• Relations 
• Tables 
– Rows 
– Columns 
• Use Object Browser to study object’s properties, 
methods.
Collection Structure 
• Properties: 
– Count 
– Item(index), 0-based index 
• Methods: 
– Clear, Add, Insert, Remove, etc.
Navigate and Display Records in 
Unbound Text Boxes 
• Use code to assign field value to the text 
box’s text property. 
• Example: 
– Dim drFound As DataRow 
– drFound = DataSet11.CUSTOMER.Rows(0) 
• Or DataSet11.Tables(“CUSTOMER”).Rows(0) 
– TextBox4.Text = drFound.Item("cname") 
• Or drFound.Item(1) 
– Or: TextBox4.Text = 
DataSet11.CUSTOMER.Rows(0).Item(1) 
– Or: DataSet21.Tables.Item("customer").Rows.Item(0).Item(1)
Implement MoveNext Button 
with Unbound Control 
If rowIndex < DataSet11.CUSTOMER.Rows.Count-1 Then 
rowIndex += 1 
TextBox1.Text = DataSet11.Tables("customer").Rows(rowIndex).Item(0) 
TextBox2.Text = DataSet11.CUSTOMER.Rows(rowIndex).Item(1) 
Else 
MsgBox("out of bound") 
End If 
Note: MovePrevious, MoveLast, MoveFirst?
Using Object Browser to Study OleDB 
Object 
• System.Data 
– System.Data.OleDB 
• OleDBConnection 
– Methods: New(), New(ConnectionString), Open(), Close() 
– Properties: ConnectionString, DataBase, Provider, TimeOut 
• OleDBCommannd 
– Methods: ExecuteReader, ExecuteNonQuery 
– Properties: Connection, CommandType, CommandText, 
Parameters 
• OleDBDataAdapter 
– Methods: Fill 
– Properties: SelectCommand, InsertCommand, DeleteCommand, 
UpdateCommand.
Searching with the Find Method 
Another Way to Bind Listbox and Display 
Selected Record 
• Create an adapter to retrieve Customer 
records and create a dataset. 
• Bind the CID field to the listbox. 
• Use the Find method of Table’s Rows 
collection to find the record. 
• Display the found record in unbound text 
boxes.
Code Example 
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As 
System.Object, ByVal e As System.EventArgs) Handles 
ListBox1.SelectedIndexChanged 
Dim drFound As DataRow 
drFound = DataSet41.CUSTOMER.Rows.Find(ListBox1.SelectedValue) 
‘ Assume SelectedValue is CID 
TextBox1.Text = drFound.Item("cname") 
TextBox2.Text = drFound.Item("rating") 
End Sub 
Note: We can get the search value from other controls such as InputBox 
and Textbox.
How to Determine If Record Exists 
or Not 
Dim foundRow As DataRow 
Dim SearchValue as String 
SearchValue=InputBox(“Enter CID”) 
foundRow = DataSet41.CUSTOMER.Rows.Find (SearchValue) 
If Not (foundRow Is Nothing) Then 
TextBox1.Text = drFound.Item("cname") 
TextBox2.Text = drFound.Item("rating") 
Else 
Messagerbox.show(“Record not exist”) 
End If
Creating Parameter Query with Adapter 
Configuration Wizard 
• Parameter query: Selection criteria is entered at 
run time. 
• Command object’s Parameters property. 
• Example: Orders table: OID, CID, Odate, 
SalesPerson 
• To create a parameter for the CID field: 
– In the Query Design window’s criteria column of the CID field, add 
criteria: =? 
• To assign the parameter value: 
– OleDbDataAdapter2.SelectCommand.Parameters("cid").Value = 
• Demo: Get CID from a InputBox and display orders.
Parameter Query Example: 
• Select CID from a listBox and display 
orders of the selected CID in a DataGrid 
– Create and bind the listbox (specify the valueMember). 
– Create a second adapter and define a parameter query. 
– In the Query Design window’s criteria column, add criteria: =? 
– Generate a 2nd dataset (DataSet21 in this example) with the 
parameter. 
– Create and bind the DataGrid to the dataset. 
– In the listbox’s SelectedIndexChanged event, assign the selected 
value to the parameter and fill the dataset: 
• DataSet21.Clear() 
• OleDbDataAdapter2.SelectCommand.Parameters("cid").Value = 
ListBox1.SelectedValue 
• OleDbDataAdapter2.Fill(DataSet21)
Display Selected Record in Text Boxes 
with Parameter Query 
• Create and bind the listbox. 
• Create a second adapter and define a parameter query. 
– In the Query Design window’s criteria column, add criteria: =? 
• Generate the dataset with the parameter. 
• Create and bind textboxes to the dataset. 
• In the listbox’s click event, assign the selected value to the 
parameter and fill the dataset: 
– DataSet11.Clear() 
– OleDbDataAdapter2.SelectCommand.Parameters("cid").Value = 
ListBox1.SelectedValue 
– OleDbDataAdapter2.Fill(DataSet11)
Send Changes in a Bound DataGrid 
Back to the Database 
• Updating records in DataGrid: 
– New records are added at the end of the grid. 
– To delete a record, click the leftmost column to select 
the record, then press the delete key. 
– Modify record 
• Add an Update button that use adapter’s update 
method to send changes back to the data source: 
– OledbDataAdapter1.Update(Dataset11)
Creating Parent/Child Form with 
Binding 
• Dataset contains Customer and Orders with 
relation CustomerOrders. 
• Bind the textboxes to Customer table. 
• Bind the datagrid to the relation: 
– DataSource: Dataset 
– DataMember: Customer/CustomerOrders 
• Note: Study the form created by the Data Form 
Wizard.

More Related Content

What's hot

Ado.net
Ado.netAdo.net
Ado.net
Vikas Trivedi
 
ADO.NET -database connection
ADO.NET -database connectionADO.NET -database connection
ADO.NET -database connection
Anekwong Yoddumnern
 
Ado.net
Ado.netAdo.net
Ado.net
dina1985vlr
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
Ngeam Soly
 
Visual Basic.Net & Ado.Net
Visual Basic.Net & Ado.NetVisual Basic.Net & Ado.Net
Visual Basic.Net & Ado.Net
FaRid Adwa
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
prabhu rajendran
 
ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
iFour Institute - Sustainable Learning
 
ADO.NET
ADO.NETADO.NET
ADO.NET
Wani Zahoor
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
DrSonali Vyas
 
ADO CONTROLS - Database usage
ADO CONTROLS - Database usageADO CONTROLS - Database usage
ADO CONTROLS - Database usage
Muralidharan Radhakrishnan
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentalsMadhuri Kavade
 
Grid Vew Control VB
Grid Vew Control VBGrid Vew Control VB
Grid Vew Control VB
sunmitraeducation
 
Ado.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksAdo.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworks
Luis Goldster
 
Ado.net
Ado.netAdo.net
Ado.net
Om Prakash
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
Randy Connolly
 
Developing Dynamic Reports for TMS Using Crystal Reports
Developing Dynamic Reports for TMS Using Crystal ReportsDeveloping Dynamic Reports for TMS Using Crystal Reports
Developing Dynamic Reports for TMS Using Crystal Reports
Chad Petrovay
 

What's hot (20)

Ado.net
Ado.netAdo.net
Ado.net
 
Ado.net
Ado.netAdo.net
Ado.net
 
ADO.NET -database connection
ADO.NET -database connectionADO.NET -database connection
ADO.NET -database connection
 
Database Connection
Database ConnectionDatabase Connection
Database Connection
 
Ado.net
Ado.netAdo.net
Ado.net
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
 
Visual Basic.Net & Ado.Net
Visual Basic.Net & Ado.NetVisual Basic.Net & Ado.Net
Visual Basic.Net & Ado.Net
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
ADO CONTROLS - Database usage
ADO CONTROLS - Database usageADO CONTROLS - Database usage
ADO CONTROLS - Database usage
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentals
 
Grid Vew Control VB
Grid Vew Control VBGrid Vew Control VB
Grid Vew Control VB
 
Ado.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksAdo.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworks
 
Ado.net
Ado.netAdo.net
Ado.net
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Ch 7 data binding
Ch 7 data bindingCh 7 data binding
Ch 7 data binding
 
2310 b 09
2310 b 092310 b 09
2310 b 09
 
Developing Dynamic Reports for TMS Using Crystal Reports
Developing Dynamic Reports for TMS Using Crystal ReportsDeveloping Dynamic Reports for TMS Using Crystal Reports
Developing Dynamic Reports for TMS Using Crystal Reports
 

Viewers also liked

Vb net xp_04
Vb net xp_04Vb net xp_04
Vb net xp_04Niit Care
 
PHP to Python with No Regrets
PHP to Python with No RegretsPHP to Python with No Regrets
PHP to Python with No RegretsAlex Ezell
 
presentation on Unix basic by prince kumar kushwhaha
presentation on Unix basic by prince kumar kushwhahapresentation on Unix basic by prince kumar kushwhaha
presentation on Unix basic by prince kumar kushwhaha
Rustamji Institute of Technology
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The Basics
Ranel Padon
 
Basic .Net Training in Hyderabad
Basic .Net Training in HyderabadBasic .Net Training in Hyderabad
Basic .Net Training in Hyderabad
Ugs8008
 
Introduction To Unix
Introduction To UnixIntroduction To Unix
Introduction To UnixCTIN
 
Python Intro For Managers
Python Intro For ManagersPython Intro For Managers
Python Intro For ManagersAtul Shridhar
 
Python Basics
Python BasicsPython Basics
Python Basics
primeteacher32
 
C programming flow of controls
C  programming flow of controlsC  programming flow of controls
C programming flow of controls
argusacademy
 
TALLY Payroll ENTRY
TALLY Payroll ENTRYTALLY Payroll ENTRY
TALLY Payroll ENTRY
argusacademy
 
TALLY Pos ENTRY
TALLY Pos ENTRYTALLY Pos ENTRY
TALLY Pos ENTRY
argusacademy
 
TALLY 1 st level entry
TALLY 1 st level entryTALLY 1 st level entry
TALLY 1 st level entry
argusacademy
 
COMPUTER Tips ‘n’ Tricks
COMPUTER Tips ‘n’   TricksCOMPUTER Tips ‘n’   Tricks
COMPUTER Tips ‘n’ Tricks
argusacademy
 
Virus
VirusVirus
1 tally basic
1 tally basic1 tally basic
1 tally basic
argusacademy
 
Application software
Application softwareApplication software
Application software
argusacademy
 
VISUAL BASIC .net i
VISUAL BASIC .net iVISUAL BASIC .net i
VISUAL BASIC .net i
argusacademy
 

Viewers also liked (20)

Attila_Hunics_IT
Attila_Hunics_ITAttila_Hunics_IT
Attila_Hunics_IT
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Vb net xp_04
Vb net xp_04Vb net xp_04
Vb net xp_04
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
PHP to Python with No Regrets
PHP to Python with No RegretsPHP to Python with No Regrets
PHP to Python with No Regrets
 
presentation on Unix basic by prince kumar kushwhaha
presentation on Unix basic by prince kumar kushwhahapresentation on Unix basic by prince kumar kushwhaha
presentation on Unix basic by prince kumar kushwhaha
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The Basics
 
Basic .Net Training in Hyderabad
Basic .Net Training in HyderabadBasic .Net Training in Hyderabad
Basic .Net Training in Hyderabad
 
Introduction To Unix
Introduction To UnixIntroduction To Unix
Introduction To Unix
 
Python Intro For Managers
Python Intro For ManagersPython Intro For Managers
Python Intro For Managers
 
Python Basics
Python BasicsPython Basics
Python Basics
 
C programming flow of controls
C  programming flow of controlsC  programming flow of controls
C programming flow of controls
 
TALLY Payroll ENTRY
TALLY Payroll ENTRYTALLY Payroll ENTRY
TALLY Payroll ENTRY
 
TALLY Pos ENTRY
TALLY Pos ENTRYTALLY Pos ENTRY
TALLY Pos ENTRY
 
TALLY 1 st level entry
TALLY 1 st level entryTALLY 1 st level entry
TALLY 1 st level entry
 
COMPUTER Tips ‘n’ Tricks
COMPUTER Tips ‘n’   TricksCOMPUTER Tips ‘n’   Tricks
COMPUTER Tips ‘n’ Tricks
 
Virus
VirusVirus
Virus
 
1 tally basic
1 tally basic1 tally basic
1 tally basic
 
Application software
Application softwareApplication software
Application software
 
VISUAL BASIC .net i
VISUAL BASIC .net iVISUAL BASIC .net i
VISUAL BASIC .net i
 

Similar to VISUAL BASIC .net data accesss vii

3. ADO.NET
3. ADO.NET3. ADO.NET
3. ADO.NET
Rohit Rao
 
ADO.NET Introduction
ADO.NET IntroductionADO.NET Introduction
ADO.NET Introduction
Yogendra Tamang
 
Marmagna desai
Marmagna desaiMarmagna desai
Marmagna desai
jmsthakur
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
Paneliya Prince
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
Dhaval Mistry
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14Sisir Ghosh
 
Synapseindia dot net development chapter 8 asp dot net
Synapseindia dot net development  chapter 8 asp dot netSynapseindia dot net development  chapter 8 asp dot net
Synapseindia dot net development chapter 8 asp dot net
Synapseindiappsdevelopment
 
Database
DatabaseDatabase
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
chhaichivon
 
Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.
Alexey Furmanov
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to adoHarman Bajwa
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
anujaggarwal49
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NET
Everywhere
 
MWLUG 2016 : AD117 : Xpages & jQuery DataTables
MWLUG 2016 : AD117 : Xpages & jQuery DataTablesMWLUG 2016 : AD117 : Xpages & jQuery DataTables
MWLUG 2016 : AD117 : Xpages & jQuery DataTables
Michael Smith
 
WEB PROGRAMMING USING ASP.NET
WEB PROGRAMMING USING ASP.NETWEB PROGRAMMING USING ASP.NET
WEB PROGRAMMING USING ASP.NET
DhruvVekariya3
 
Vb.net session 16
Vb.net session 16Vb.net session 16
Vb.net session 16Niit Care
 
How Clean is your Database? Data Scrubbing for all Skill Sets
How Clean is your Database? Data Scrubbing for all Skill SetsHow Clean is your Database? Data Scrubbing for all Skill Sets
How Clean is your Database? Data Scrubbing for all Skill Sets
Chad Petrovay
 
Linq to sql
Linq to sqlLinq to sql
Linq to sql
Muhammad Younis
 

Similar to VISUAL BASIC .net data accesss vii (20)

3. ADO.NET
3. ADO.NET3. ADO.NET
3. ADO.NET
 
Ado
AdoAdo
Ado
 
ADO.NET Introduction
ADO.NET IntroductionADO.NET Introduction
ADO.NET Introduction
 
Marmagna desai
Marmagna desaiMarmagna desai
Marmagna desai
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14
 
Synapseindia dot net development chapter 8 asp dot net
Synapseindia dot net development  chapter 8 asp dot netSynapseindia dot net development  chapter 8 asp dot net
Synapseindia dot net development chapter 8 asp dot net
 
Database
DatabaseDatabase
Database
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
 
Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NET
 
MWLUG 2016 : AD117 : Xpages & jQuery DataTables
MWLUG 2016 : AD117 : Xpages & jQuery DataTablesMWLUG 2016 : AD117 : Xpages & jQuery DataTables
MWLUG 2016 : AD117 : Xpages & jQuery DataTables
 
WEB PROGRAMMING USING ASP.NET
WEB PROGRAMMING USING ASP.NETWEB PROGRAMMING USING ASP.NET
WEB PROGRAMMING USING ASP.NET
 
Vb.net session 16
Vb.net session 16Vb.net session 16
Vb.net session 16
 
How Clean is your Database? Data Scrubbing for all Skill Sets
How Clean is your Database? Data Scrubbing for all Skill SetsHow Clean is your Database? Data Scrubbing for all Skill Sets
How Clean is your Database? Data Scrubbing for all Skill Sets
 
Crystal report
Crystal reportCrystal report
Crystal report
 
Linq to sql
Linq to sqlLinq to sql
Linq to sql
 

More from argusacademy

Css & dhtml
Css  & dhtmlCss  & dhtml
Css & dhtml
argusacademy
 
Html table
Html tableHtml table
Html table
argusacademy
 
Html ordered & unordered list
Html ordered & unordered listHtml ordered & unordered list
Html ordered & unordered list
argusacademy
 
Html level ii
Html level  iiHtml level  ii
Html level ii
argusacademy
 
Html frame
Html frameHtml frame
Html frame
argusacademy
 
Html forms
Html formsHtml forms
Html forms
argusacademy
 
Html creating page link or hyperlink
Html creating page link or hyperlinkHtml creating page link or hyperlink
Html creating page link or hyperlink
argusacademy
 
Html basic
Html basicHtml basic
Html basic
argusacademy
 
Java script
Java scriptJava script
Java script
argusacademy
 
Php string
Php stringPhp string
Php string
argusacademy
 
Php session
Php sessionPhp session
Php session
argusacademy
 
Php opps
Php oppsPhp opps
Php opps
argusacademy
 
Php oops1
Php oops1Php oops1
Php oops1
argusacademy
 
Php if else
Php if elsePhp if else
Php if else
argusacademy
 
Php creating forms
Php creating formsPhp creating forms
Php creating forms
argusacademy
 
Php create and invoke function
Php create and invoke functionPhp create and invoke function
Php create and invoke function
argusacademy
 
Php basic
Php basicPhp basic
Php basic
argusacademy
 
Php array
Php arrayPhp array
Php array
argusacademy
 
Sql query
Sql querySql query
Sql query
argusacademy
 
Rdbms
RdbmsRdbms

More from argusacademy (20)

Css & dhtml
Css  & dhtmlCss  & dhtml
Css & dhtml
 
Html table
Html tableHtml table
Html table
 
Html ordered & unordered list
Html ordered & unordered listHtml ordered & unordered list
Html ordered & unordered list
 
Html level ii
Html level  iiHtml level  ii
Html level ii
 
Html frame
Html frameHtml frame
Html frame
 
Html forms
Html formsHtml forms
Html forms
 
Html creating page link or hyperlink
Html creating page link or hyperlinkHtml creating page link or hyperlink
Html creating page link or hyperlink
 
Html basic
Html basicHtml basic
Html basic
 
Java script
Java scriptJava script
Java script
 
Php string
Php stringPhp string
Php string
 
Php session
Php sessionPhp session
Php session
 
Php opps
Php oppsPhp opps
Php opps
 
Php oops1
Php oops1Php oops1
Php oops1
 
Php if else
Php if elsePhp if else
Php if else
 
Php creating forms
Php creating formsPhp creating forms
Php creating forms
 
Php create and invoke function
Php create and invoke functionPhp create and invoke function
Php create and invoke function
 
Php basic
Php basicPhp basic
Php basic
 
Php array
Php arrayPhp array
Php array
 
Sql query
Sql querySql query
Sql query
 
Rdbms
RdbmsRdbms
Rdbms
 

Recently uploaded

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 

Recently uploaded (20)

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 

VISUAL BASIC .net data accesss vii

  • 2. Microsoft Universal Data Access • ODBC: Open Database Connectivity – A driver manager – Used for relational databases • OLE DB: The OLE database protocol – Allows a program to access information in many types of data source. – Data provider: databases, spreadsheets, etc. • ADO.NET: ActiveX Data Objects – An Interface for OLE DB. – Allow programmers to use a standard set of objects to refer to any OLE DB data source.
  • 3. .Net Applications OLE DB Provider OLE DB Data Source ADO.Net OLE DB Provider ODBC ODBC Data Source SQL Server .Net Data Provider SQL Server Data Source OLE DB .Net Data Provider
  • 4. Using ODBC • Windows 2000/2003: • Control Panel /Administrative Tools/DataSource(ODBC) • Three types of data source names – User DSN: usable only by you and only on the machine currently using. – System DSN: Any one using the machine can use. – File DSN: Can be copied and used by other computers with the same driver installed.
  • 5. VB.NET Database Tools • Database connection: – Tool/Connect to database • Provider:MS Jet 4.0 OLE DB Provider • Connection • Server Explorer – Data connections: • Right click and Add Connection • Tables, Views • Toolbox:Data tab • Data Form Wizard
  • 6. Steps to Retrieve Data • Establishes a connection to the database. • Executes commands against the database. • Store data results.
  • 7. ADO.NET Objects .NET Applications Data Set Data Reader Adapter Command Object Connection Object Database
  • 8. ADO.NET Objects • Connection Object: Represent a connection to the database. • Command Object: The command object allows us to execute a SQL statement or a stored procedure. • DataReader: It is a read-only and forward-only pointer into a table to retrieve records. • DataSet Object: A DataSet object can hold several tables and relationships between tables. • DataAdapter: This the object used to pass data between the database and the dataset.
  • 9. How to create an ADO.Net object? • Using Wizard – Data Form Wizard – Data Adapter Wizard • Using code: – Example: – dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:sales2k.mdb" – dim objConn as new OledbConnection(strConn) – objConn.open()
  • 10. Data Form Wizard • Creating a form with ADO.Net objects and data-bound controls to display and update information in a dataset. • Demo: Using Data Form Wizard to create a navigational form. – Project/Add Windows Form/Data Form Wizard – Set connection – Choose tables – Display records in grid or in text boxes.
  • 11. Adapter & Dataset Context Menu • Adapter: – Properties: • Command objects – Configure Adapter – Generate dataset – Preview data • Dataset: – View Schema: Dataset/XML
  • 12. Other Data Form Demos • Display records in text boxes. • Add /Modify/Delete records. • Hierarchical forms: – Parent/Child relationship
  • 13. Creating A Database Application Without Programming • Creating a database application to display information and update database. • A main form with buttons to open data forms: – DisplayInfo – Enter New – Modify – Exit
  • 14. Data Adapter Wizard • Configure Data Adapter and generating a dataset: – Drag OledbDataAdapter (or database’s table) to the form. – Use the Data Adapter Wizard to configure the Adapter. – Right Click the Adapter to preview data and creating dataset. • Bind the dataset to controls.
  • 15. Data Binding • Connect a control or property to one or more data elements. • Simple binding: Use simple binding to display a field value in controls that show Data Bindings in the property window, such as text box or label. • Complex binding: Use complex binding to bind more than one field to controls such as DataGrid and list box. Use the control’s Data Source and Data Member to bind the data.
  • 16. Creating Bound Controls • DataGrid control: – Data Source property – Data Member property – In the Form Load event, use Adapter’s Fill method to load the dataset: • OleDbDataAdapter1.Fill(DataSet11)
  • 17. Binding Text Box • Data Bindings property: – Text: choose field • Add navigation buttons: – The current record position within the dataset is stored in a form’s BindingContext’s Position property. This position is zero based. Add one move to the next record, minus one move to the previous record.
  • 18. MoveNext and MoveLast Example • MoveNext: – Me.BindingContext(DataSet21, "customer").Position += 1 • MoveLast: – Me.BindingContext(DataSet21, "customer").Position = Me.BindingContext(DataSet21, "customer").Count -1 • How to MovePrevious and MoveFirst? • Note: The Position property takes care of the end of file automatically.
  • 19. CurrencyManager • Dim custCurrMgr As CurrencyManager • Dim ordCurrMgr As CurrencyManager • In a procedure: – ordCurrMgr = Me.BindingContext(Ds31, "orders") – custCurrMgr = Me.BindingContext(Ds31, “customer") – custCurrMgr.Position += 1 – ordCurrMgr.Position += 1
  • 20. Binding DataGrid • From Server Explorer, drag the table from a database connection (or from Data tab, drag a oleDbAdapter) onto the form. • Create dataset. • Drag DataGrid and set the DataSource and Data Member property. • Use adapter’s Fill method to load the dataset.
  • 21. Displaying Many Tables with One DataGrid • Define one Adapter for each table. • Create the dataset with multiple tables. • Add a DataGrid control and set the DataSource proeprty to the dataset name and leave the DataMember property blank.
  • 22. Creating Hierarchical Data Grid • Define two Adapters, one for the parent table and one for the child table. • Create the dataset. • Right-click the dataset to View Schema • Right-click the parent table and choose Add/New Relation • Add a DataGrid control and set the DataSource proeprty to the dataset.parentTable and leave the DataMember property blank. • Note: DO File/SaveAll after creating the relation.
  • 23. Binding ListBox • Example: Bind Customer Table’s CID field to a listbox. – Create a Adapter to retrieve CID (and Cname) fields , and generate the dataset. – Add ListBox and set binding properties: • Data Source • Display Member • Value Member: the actual values for items in the list box. To display the selected item’s value in a text box, do: – Textbox1.text = ListBox1.SelectedValue • Can we use TextBox1.text=ListBox1.SelectedItem? No!
  • 24. Display Selected Record • Bound textbox: – Me.BindingContext(DataSet11, "customer").Position = ListBox1.SelectedIndex – • Unbound textbox
  • 25. ListBox SelectedItem Property • How to display the selected record in unbound textbox? • After binding to a data source, this property return a DataRowView object. • What is DataRowView? – Object Browser: • System.Data – System.Data » DataRowView: Item property • To retrieve a column from a DataRowView object (use 0-based index to identity a column): • ListBox1.SelectedItem.Item(1) • Or: ListBox1.SelectedItem(1) • Or: ListBox1.SelectedItem(“Cname”)
  • 26. Using Object Browser • View/Object Browser • DataSet object model: • System.Data – DataSet • Relations • Tables – Rows – Columns • Use Object Browser to study object’s properties, methods.
  • 27. Collection Structure • Properties: – Count – Item(index), 0-based index • Methods: – Clear, Add, Insert, Remove, etc.
  • 28. Navigate and Display Records in Unbound Text Boxes • Use code to assign field value to the text box’s text property. • Example: – Dim drFound As DataRow – drFound = DataSet11.CUSTOMER.Rows(0) • Or DataSet11.Tables(“CUSTOMER”).Rows(0) – TextBox4.Text = drFound.Item("cname") • Or drFound.Item(1) – Or: TextBox4.Text = DataSet11.CUSTOMER.Rows(0).Item(1) – Or: DataSet21.Tables.Item("customer").Rows.Item(0).Item(1)
  • 29. Implement MoveNext Button with Unbound Control If rowIndex < DataSet11.CUSTOMER.Rows.Count-1 Then rowIndex += 1 TextBox1.Text = DataSet11.Tables("customer").Rows(rowIndex).Item(0) TextBox2.Text = DataSet11.CUSTOMER.Rows(rowIndex).Item(1) Else MsgBox("out of bound") End If Note: MovePrevious, MoveLast, MoveFirst?
  • 30. Using Object Browser to Study OleDB Object • System.Data – System.Data.OleDB • OleDBConnection – Methods: New(), New(ConnectionString), Open(), Close() – Properties: ConnectionString, DataBase, Provider, TimeOut • OleDBCommannd – Methods: ExecuteReader, ExecuteNonQuery – Properties: Connection, CommandType, CommandText, Parameters • OleDBDataAdapter – Methods: Fill – Properties: SelectCommand, InsertCommand, DeleteCommand, UpdateCommand.
  • 31. Searching with the Find Method Another Way to Bind Listbox and Display Selected Record • Create an adapter to retrieve Customer records and create a dataset. • Bind the CID field to the listbox. • Use the Find method of Table’s Rows collection to find the record. • Display the found record in unbound text boxes.
  • 32. Code Example Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Dim drFound As DataRow drFound = DataSet41.CUSTOMER.Rows.Find(ListBox1.SelectedValue) ‘ Assume SelectedValue is CID TextBox1.Text = drFound.Item("cname") TextBox2.Text = drFound.Item("rating") End Sub Note: We can get the search value from other controls such as InputBox and Textbox.
  • 33. How to Determine If Record Exists or Not Dim foundRow As DataRow Dim SearchValue as String SearchValue=InputBox(“Enter CID”) foundRow = DataSet41.CUSTOMER.Rows.Find (SearchValue) If Not (foundRow Is Nothing) Then TextBox1.Text = drFound.Item("cname") TextBox2.Text = drFound.Item("rating") Else Messagerbox.show(“Record not exist”) End If
  • 34. Creating Parameter Query with Adapter Configuration Wizard • Parameter query: Selection criteria is entered at run time. • Command object’s Parameters property. • Example: Orders table: OID, CID, Odate, SalesPerson • To create a parameter for the CID field: – In the Query Design window’s criteria column of the CID field, add criteria: =? • To assign the parameter value: – OleDbDataAdapter2.SelectCommand.Parameters("cid").Value = • Demo: Get CID from a InputBox and display orders.
  • 35. Parameter Query Example: • Select CID from a listBox and display orders of the selected CID in a DataGrid – Create and bind the listbox (specify the valueMember). – Create a second adapter and define a parameter query. – In the Query Design window’s criteria column, add criteria: =? – Generate a 2nd dataset (DataSet21 in this example) with the parameter. – Create and bind the DataGrid to the dataset. – In the listbox’s SelectedIndexChanged event, assign the selected value to the parameter and fill the dataset: • DataSet21.Clear() • OleDbDataAdapter2.SelectCommand.Parameters("cid").Value = ListBox1.SelectedValue • OleDbDataAdapter2.Fill(DataSet21)
  • 36. Display Selected Record in Text Boxes with Parameter Query • Create and bind the listbox. • Create a second adapter and define a parameter query. – In the Query Design window’s criteria column, add criteria: =? • Generate the dataset with the parameter. • Create and bind textboxes to the dataset. • In the listbox’s click event, assign the selected value to the parameter and fill the dataset: – DataSet11.Clear() – OleDbDataAdapter2.SelectCommand.Parameters("cid").Value = ListBox1.SelectedValue – OleDbDataAdapter2.Fill(DataSet11)
  • 37. Send Changes in a Bound DataGrid Back to the Database • Updating records in DataGrid: – New records are added at the end of the grid. – To delete a record, click the leftmost column to select the record, then press the delete key. – Modify record • Add an Update button that use adapter’s update method to send changes back to the data source: – OledbDataAdapter1.Update(Dataset11)
  • 38. Creating Parent/Child Form with Binding • Dataset contains Customer and Orders with relation CustomerOrders. • Bind the textboxes to Customer table. • Bind the datagrid to the relation: – DataSource: Dataset – DataMember: Customer/CustomerOrders • Note: Study the form created by the Data Form Wizard.