ADO.NET Object Model

પાંચ objects, દરેકનું એક job: Connection line ને open કરે છે, Command SQL ને carry કરે છે, DataReader connected હોય ત્યારે rows ને stream કરે છે, DataAdapter disconnected work માટે DataSet ને fill કરે છે: exam નું favourite table.

10 min read · 10 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

till અને vault વચ્ચે પાંચ workers

ShopKeeper ના form અને ShopDB file વચ્ચે નાનો crew sits કરે છે, અને .NET માં તમે જે દરેક database program લખો છો તે same 5 workers ને hire કરે છે.

એક phone line ને open રાખે છે. એક તમારા SQL sentence ને carry કરે છે. એક જવાબો ને line live હોય ત્યારે તમારી પાસે back read કરે છે. એક full pickup-and-delivery કરે છે જેથી તમે hang up કરી શકો. અને એક જે તમે already જાણો છો: Unit 3 નો in-memory register.

5 ને name કરો, દરેક નું single job જાણો, અને આ unit ના theory questions already answered છે.

Theory

wholesaler ને calling

ShopDB ને town ની બીજી બાજુ wholesaler તરીકે think કરો.

Connection એ phone line છે: number (connection string) સાથે dialled, opened, eventually hung up. Command એ sentence છે જે તમે બોલો છો: order, SQL માં. DataReader live call પર listening કરે છે, items ને read out થતા scribbling કરે છે, પાછા જવા નહીં, editing નહીં. DataAdapter એ delivery boy છે: એક trip, આખો order home લાવે છે, જ્યાં તે તમારા own register (DataSet) માં sits કરે છે call end થયા પછી work કરવા માટે.

At a glance

ADO.NET object model (આ table ને learn કરો)

Objectએક jobKey members
Connectiondatabase ની open lineConnectionString, Open(), Close()
Commandએક SQL statement ને carry કરે છેCommandText, ExecuteReader, ExecuteNonQuery, ExecuteScalar
DataReaderresult rows ને stream કરે છે, connectedRead(), item access rd("Amount")
DataAdapterdisconnected world નો bridgeFill(ds), Update(ds)
DataSetIn-memory, offline copy (Unit 3)Tables, Rows

Theory

બે working styles

5 workers 2 teams બનાવે છે, અને split એ આ unit ની THE concept છે:

  • Connected: Connection + Command + DataReader. line તમે read કરો ત્યારે open રહે છે; fastest, always-current, પણ reader forward-only અને read-only છે, અને database તમારા call ને whole time hold કરે છે.
  • Disconnected: Connection + DataAdapter + DataSet. એક trip માં everything fetch કરો, hang up, પછી browse, edit અને grids ને offline bind કરો; Update() changes ને later sync back કરે છે.

ShopKeeper bill ને reader થી print કરે છે (quick pass), પણ day-report screen ને adapter જોઈએ છે (browse offline, કોઈ line held open નહીં).

Theory

Providers: same crew, different uniforms

ADO.NET દરેક database brand માટે એક crew ship કરે છે, જેને provider કહેવામાં આવે છે:

  • SQL Server માટે System.Data.SqlClient: SqlConnection, SqlCommand, SqlDataReader, SqlDataAdapter
  • Access files માટે System.Data.OleDb: OleDbConnection, OleDbCommand, અને so on

Same 5 roles, same members, ફક્ત prefix changes થાય છે. અને notice કરો કે કયા object પર કોઈ prefix નથી: DataSet provider-neutral છે, કારણ કે એકવાર data memory માં હોય, તેની origin no longer matters. એ detail એ recurring 1-marker છે.

Quiz

કયો ADO.NET object connected, forward-only અને read-only છે?

  1. DataSet
  2. DataAdapter
  3. DataReader
  4. Command
Show the answer

DataReader

એ 3-word signature (connected, forward-only, read-only) IS DataReader નું exam fingerprint: તે live connection થી rows ને stream કરે છે, rewind નથી કરી શકતું, edit નથી કરી શકતું. DataSet એ દરેક word પર તેનું near-opposite છે: disconnected, freely navigable, editable. DataAdapter એ 2 worlds વચ્ચે courier છે, કંઈ નો reader નથી. Command ફક્ત SQL ને carry કરે છે; તે reader ને return કરે છે પણ એક નથી. fingerprint phrase ને memorise કરો: examiners તેને verbatim quote કરે છે.

Think first

2 screens ને staff કરો

Screen A: cashier bill 42 ને reprints કરે છે, તેની rows પર એક quick pass. Screen B: owner ઘરે bills ના month ને browse કરે છે, remarks ને edit કરે છે, later sync કરે છે. દરેક screen ને તેની objects ની team assign કરો tap કરતા પહેલા.

Show the answer

Screen A: connected team: SqlConnection (open), SqlCommand (SELECT ... WHERE BillNo = 42), SqlDataReader (એક forward pass, print, close): minimal, fast, done. Screen B: disconnected team: SqlDataAdapter એક trip માં DataSet ને fill કરે છે, connection closes થાય છે, owner offline bound grid માં work કરે છે, અને da.Update(ds) edited remarks ને convenient હોય ત્યારે post કરે છે. Choosing rule: quick single pass = reader; browse, edit અથવા work offline = adapter + DataSet.

Watch out

Model mix-ups જે marks cost કરે છે

DataReader vs DataSet: pair જે exams love to swap કરે છે. Reader = connected stream; DataSet = offline copy. ક્યારેય ન લખો કે DataSet forward-only છે.

DataAdapter as a container: તે કંઈ hold નથી કરતું; તે data ને MOVE કરે છે (Fill in, Update out).

એક Command, એક statement: તેનું CommandText એ single SQL sentence છે; 3 different queries એટલે 3 commands (અથવા calls વચ્ચે CommandText ને rewrite કરવું).

Theory

model એ Unit 3 ની missing half છે

register-and-glass lesson ને યાદ કરો: આપણે promise કર્યું હતું કે DataSet એક day real database થી fill થશે grid ને notice કર્યા વગર. DataAdapter એ તે promise નો delivery mechanism છે, અને next lesson તેને code માં execute કરે છે: open, query, read, insert, fill, bind: complete ShopKeeper save-and-reload cycle, BCA205 ના SQL સાથે Command objects ની અંદર riding.

Summary

Key takeaways

  • પાંચ objects, દરેકનું એક job: Connection (line), Command (SQL), DataReader (connected stream), DataAdapter (courier), DataSet (offline copy).
  • Connected style: Connection + Command + DataReader: fast, live, forward-only, read-only.
  • Disconnected style: DataAdapter DataSet ને fill કરે છે, connection closes થાય છે, offline work કરો, Update sync back કરે છે.
  • Command ના 3 executes: ExecuteReader (rows), ExecuteNonQuery (affected count), ExecuteScalar (single value).
  • Providers crew ને rename કરે છે: SQL Server માટે Sql, Access માટે OleDb; DataSet provider-neutral રહે છે.
  • Quick pass = reader; browse/edit/offline = adapter + DataSet.
  • Memory hook: line, sentence, listener, courier, register.

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Database access using ADO.NET

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

ADO.NET Object Model · .NET Programming · Gri-Learn