Introduction:
Here I will explain Creating a Custom Data Adapter in Asp.Net.
Description:
Previous article i will explain Entity Data model ,DataTable Event. now i will explain Creating a Custom Data Adapter in Asp.Net .
The OleDbCommand object
OleDbCommand uCmd = new OleDbCommand("UPDATE Property SET Name=? WHERE PropertyID=?", dbConnection); uCmd.Parameters.Add(new System.Data.OleDb.OleDbParameter("Name", System.Data.OleDb.OleDbType.Char,50); uCmd.Parameters.Add(new System.Data.OleDb.OleDbParameter("PropertyID", System.Data.OleDb.OleDbType.Numeric,0);
Plugging your OleDbCommands into the OleDbDataAdapter
OleDbDataAdapter myAdapter = new OleDbDataAdapter("SELECT PropertyID, Name FROM Property", dbConnection); OleDbCommand iCmd = new OleDbCommand("INSERT INTO Property (Name) VALUES (?)", dbConnection); iCmd.Parameters.Add(new OleDbParameter("Name", OleDbType.Char, 50)); myAdapter.InsertCommand=iCmd; OleDbCommand uCmd = new OleDbCommand("UPDATE Property SET Name=? WHERE PropertyID=?", dbConnection); uCmd.Parameters.Add(new OleDbParameter("Name", OleDbType.Char, 50)); uCmd.Parameters.Add(new OleDbParameter("PropertyID", OleDbType.Numeric, 0)); myAdapter.UpdateCommand=uCmd; OleDbCommand dCmd = new OleDbCommand("DELETE FROM Property WHERE PropertyID=?", dbConnection); dCmd.Parameters.Add(new OleDbParameter("PropertyID", OleDbType.Numeric, 0)); myAdapter.DeleteCommand=dCmd;
Table Structure
Table:Property
PropertyID=Numeric
Name=Char(50)
0 comments :
Post a Comment