Database: Data > add new datasource ALGEMEEN



Similar documents
Creating the Product Catalog Part I (continued)

Apprenda.NET Developer Tutorial

listboxgaatmee.dragdrop += new DragEventHandler(listBox_DragDrop); ListBox from = (ListBox)e.Data.GetData(typeof(ListBox));

Apprenda SaaS Developer Tutorial

IP-NBM. Copyright Capgemini All Rights Reserved

Access Data Object (cont.)

Relationele Databases 2002/2003

Building ASP.NET Applications

var context = new CustomerContext(); //... context code...

OGH: : 11g in de praktijk

De tarieven van Proximus Niet meer gecommercialiseerde Bizz packs

Handleiding Process Portal

Tuesday, February 26, Unit testen in de praktijk

Data Driven Strategy. BlinkLane Consul.ng Amsterdam, 10 december Ralph Hofman Arent van t Spijker

AD A O.N. ET E Access Data Object

The state of DIY. Mix Express DIY event Maarssen 14 mei 2014

UvA college Governance and Portfolio Management

Met wie moet je als erasmusstudent het eerst contact opnemen als je aankomt?

employager 1.0 design challenge

Citrix Access Gateway: Implementing Enterprise Edition Feature 9.0

Security Assessment Report

Using IRDB in a Dot Net Project

PROCEDURE INSERTION(NUM IN EMPLOYES.NUMEMP%TYPE, NOM VARCHAR2, PRENOM IN VARCHAR2, PPHOTO IN BLOB, SALAIRE IN NUMBER);

Virtualisatie. voor desktop en beginners. Gert Schepens Slides & Notities op gertschepens.be

Network Assessment Client Risk Report Demo

Installing and activating the DCA

Examen Software Engineering /09/2011

GMP-Z Annex 15: Kwalificatie en validatie

ISACA Roundtable. Cobit and 7 september 2015

UPI 002 Taak Risico Analyse (TRA)

Risk-Based Monitoring

Storage in Microsoft Azure Wat moet ik daarmee? Bert

VBScript Database Tutorial Part 1

Instructies Tester Update DEHNrecord DRC LC M3

Software product management. Inge van de Weerd

Inhoudsopgave. Vak: Web Analysis 1 Vak: Web Information 1 Vak: Web Science 2 Vak: Web Society 3 Vak: Web Technology 4

Title page. Title: A conversation-analytic study of time-outs in the Dutch national volleyball. competition. Author: Maarten Breyten van der Meulen

HR Transformation and Future of HR Brussel, 25 april 2013 Material part 1/2

Load Balancing Lync Jaap Wesselius

Cisco Small Business Fast Track Pricing Initiative

Netezza S's. Robert Hartevelt 31 October IBM Corporation IBM Corporation IBM Corporation

Table of contents. 2. Technical details Protocols used Messaging security Encoding Input and output...

Self-test SQL Workshop

Assuring the Cloud. Hans Bootsma Deloitte Risk Services +31 (0)

G O L D C O L L E C T I O N

Hoofdstuk 2 Samenwerking en afstemming in de zorgketen

Engineering Natural Lighting Experiences

ruimtelijk ontwikkelingsbeleid

tablet technologie in het onderwijs

Shopper Marketing Model: case Chocomel Hot. Eric van Blanken 20th October 2009

ABN AMRO Bank N.V. The Royal Bank of Scotland N.V. ABN AMRO Holding N.V. RBS Holdings N.V. ABN AMRO Bank N.V.

The Chinese market for environmental and water technology. Kansendossier China

Maximizer Synergy. BE Houwaartstraat 200/1 BE 3270 Scherpenheuvel. Tel: Fax:

~ We are all goddesses, the only problem is that we forget that when we grow up ~

IT-waardeketen management op basis van eeuwenoude supply chain kennis

Use of trademarks with a reputation as Adwords by competitors: Permissible comparative advertising or impermissible coat-tail riding / dilution?

Goedgekeurde mechanische beveiligingen voor tweewielige voertuigen d.d (Approved mechanical security systems for two-wheeld vehicles)

Doorstroommogelijkheden in 3TU-verband in 2008 en 2009

The information in this report is confidential. So keep this report in a safe place!

Wiskunde op het internet

Implementeren van HL7v3 Web Services

On sorter/ picking system. Without racking. With racking. racking. racking. Compact storage racking. Mobile. Drive-in racking. Block stack.

Lokaal Netwerk Regelgeving

VB.NET - DATABASE ACCESS

Exam Ref : Developing Windows Azure and Web Services. William Ryan Wouter de Kort Shane Milton

GMP-Z Hoofdstuk 4 Documentatie. Inleiding

Digitale muziekbewerking en productie

Making, Moving and Shaking a Community of Young Global Citizens Resultaten Nulmeting GET IT DONE

D-ID. Module WP 3 Version /02/2014. Project Author(s) Dynamic Identity EF. Reviewer(s)

World Of Technology and Science Hoe stel je een testplan op

Public. Big Data in ASML. Durk van der Ploeg. ASML System Engineering Product Industrialization, October 7, 2014 NTS Eindhoven

How To Design A 3D Model In A Computer Program

Sample test Secretaries/administrative. Secretarial Staff Administrative Staff

POWER OF ATTORNEY FOR EXTRAORDINARY SHAREHOLDERS MEETING OF OCTOBER 5, 2011

Intermediate ASP.NET Web Development with C# Instructor: Frank Stepanski. Data Sources on the Web

What can Office 365 do for your organization? Cor Kroon

Windows Azure Push Notifications

Oversight Management: een zinvolle aanvulling!

Handboek scripts voor kdesrc-build

HOE WERKT CYBERCRIME EN WAT KAN JE ER TEGEN DOEN? Dave Maasland Managing Director ESET Nederland

CMMI version 1.3. How agile is CMMI?

Exhibit 3G. Annual communication ("jaarcommuniqué / communiqué annuel") of 19 March 2007

Individual project 2010: Kick- off. 13 April 2010

NL VMUG UserCon March

Transcription:

Database: Data > add new datasource ALGEMEEN een file "App.config" - <appsettings> - Voor alles wat je opvraagt een key en een value <add key="..." value=""/> key vb select/delete/update/insert - <connectionstrings>: 2 connections: - <add name="..." connectionstring="server=localhost;user id=root;password="e=mc**2";database=classicmodels" providername="mysql.data.mysqlclient"/> <configuration> <appsettings> <add key="select_customers" value="select * from customers"/> <add key="select_customer" value="select * from customers where customernumber = @customernumber" /> <add key="delete_customer" value="delete from customers where customernumber = @customernumber"/> <add key="update_customer" value="update customers set customernumber=@customernumber, customername=@customername,contactlastname=@contactlastname, contactfirstname=@contactfirstname,phone=@phone, addressline1=@addressline1,addressline2=@addressline2, city=@city,state=@state,postalcode=@postalcode,country=@country, salesrepemployeenumber=@salesrepemployeenumber, creditlimit=@creditlimit"/> <add key="insert_customer" value="insert into customers (customernumber,customername, contactlastname,contactfirstname,phone,addressline1,addressline2, city,state,postalcode,country,salesrepemployeenumber,creditlimit) values (@customernumber,@customername,@contactlastname, @contactfirstname, @phone,@addressline1,@addressline2,@city,@state, @postalcode,@country,@salesrepemployeenumber,@creditlimit)"/> </appsettings> <connectionstrings> <add name="classicmodels" connectionstring="server=localhost;user id=gast; Password=gast;database=classicmodels" providername="mysql.data.mysqlclient" /> <add name="winkel.properties.settings.classicmodelsconnectionstring" connectionstring="server=localhost;user Id=root;password=" e=mc**2";persist Security Info=True;database=classicmodels" providername="mysql.data.mysqlclient" /> </connectionstrings> </configuration>

DATAREADERS "DataStorage" waar je al het lezen en opslaan inzet -Imports -Datamembers: ConnectionStringSettings en DbProviderFactory -Constructor -GetConnection -CreateCommand -CreateParam -InsertProduct -functie die een lijst van de dingen die je opvraagt teruggeeft -void insertiets(iets blah) using System.Data.Common; using System.Configuration; using System.Data; private ConnectionStringSettings connstringset; private DbProviderFactory factory; public DataStorage() This.connStringSet = ConfigurationManager.ConnectionStrings["classicmodels"]; ; factory = DbProviderFactories.GetFactory(connStringSet.ProviderName); protected DbConnection GetConnection() DbConnection connection = factory.createconnection(); connection.connectionstring = connstringset.connectionstring; return connection; private DbCommand CreateCommand(DbConnection conn, DbTransaction trans, string text) DbCommand command = conn.createcommand(); command.transaction = trans; command.commandtext = text; return command; private DbParameter CreateParam(DbCommand command, string parameter, string value) DbParameter param = command.createparameter(); param.parametername = parameter; param.dbtype = DbType.String; param.value = value; return param; public void InsertProduct(Product p)

// verbinding met de gegevensbank DbConnection conn = GetConnection(); // commando-object aanmaken DbCommand command = CreateCommand(conn, ConfigurationManager.AppSettings["insert_products"]); // zoekopdracht uitvoeren try command.parameters.add(createparam(command, "@productcode", p.productcode)); command.parameters.add(createparam(command, "@productname", p.productname)); command.parameters.add(createparam(command, "@productline", p.productline)); command.parameters.add(createparam(command, "@productscale", p.productscale)); command.parameters.add(createparam(command, "@productvendor", p.productvendor)); command.parameters.add(createparam(command, "@productdescription", p.productdescription)); command.parameters.add(createparam(command, "@quantityinstock", p.quantity)); command.parameters.add(createparam(command, "@buyprice", p.price)); command.parameters.add(createparam(command, "@MSRP", p.msrp)); conn.open(); command.executenonquery(); catch (Exception e) Console.WriteLine(e.StackTrace); finally conn.close(); public List<Product> SelectProducts() List<Product> producten = new List<Product>(); Idem vorig try DbDataReader reader = command.executereader(); while (reader.read()) Product p = new Product(); p.productcode = reader["productcode"].tostring(); p.productname = reader["productname"].tostring(); p.productline = reader["productline"].tostring(); p.productscale = reader["productscale"].tostring(); p.productvendor = reader["productvendor"].tostring(); p.productdescription = reader["productdescription"].tostring(); p.quantity = reader.getint32(6); p.price = reader.getdouble(7); p.msrp = reader.getdouble(8); producten.add(p); idem vorig public void insertorder(order ord) // verbinding met de gegevensbank DbConnection conn = GetConnection(); conn.open(); DbTransaction trans = conn.begintransaction(); try

// commando-object aanmaken DbCommand comorders = CreateCommand(conn,trans, ConfigurationManager.AppSettings["insert_orders"]); comorders.parameters.add(createparam(comorders, "@ordernumber", ord.number)); comorders.parameters.add(createparam(comorders, "@orderdate", ord.ordered)); comorders.parameters.add(createparam(comorders, "@requireddate", ord.required)); comorders.parameters.add(createparam(comorders, "@shippeddate", ord.shipped)); comorders.parameters.add(createparam(comorders, "@status", ord.status)); comorders.parameters.add(createparam(comorders, "@comments", ord.comments)); comorders.parameters.add(createparam(comorders, "@customernumber", ord.customernumber)); comorders.executenonquery(); foreach (OrderDetail detail in ord.details) DbCommand comorderdetails = CreateCommand(conn, trans, ConfigurationManager.AppSettings["insert_orderdetails"]); "@ordernumber",ord.number)); "@productcode",detail.productcode)); "@quantityordered",detail.quantity)); "@priceeach",detail.price)); "@orderlinenumber",detail.orderlinenumber)); comorderdetails.executenonquery(); trans.commit(); idem vorig Voor alles wat je opvraagt een klasse (vb product/order/...) - zoek in de databank (.xsd file) welke parameters elke klasse moet hebben - getters en setters voor alles (insert snippet) Je hoofdprogramma: "Program.cs" DataAdapter en DataSet Enkel program.cs en AdapterDatastorage.cs - AdapterDatastorage -Dataleden: private DbDataAdapter customeradapter; -private void setcolumnenversion(ref DbParameter parm, string parameter, DbType type, string column, DataRowVersion version) parm.parametername = parameter; parm.dbtype = type; parm.sourcecolumn = column; parm.sourceversion = version;

-private DbCommand createcommand(dbconnection conn, string text) DbCommand command = conn.createcommand(); command.commandtext = text; return command; -public AdapterDatastorage() ConnectionStringSettings connstring = ConfigurationManager.ConnectionStrings["classicmodels"]; DbProviderFactory factory = DbProviderFactories.GetFactory(connString.ProviderName); customeradapter = factory.createdataadapter(); DbConnection connection = factory.createconnection(); customeradapter.missingschemaaction = MissingSchemaAction.AddWithKey; connection.connectionstring = connstring.connectionstring; customeradapter.selectcommand = createcommand(connection, ConfigurationManager.AppSettings["select_customers"]); DbCommand commando = createcommand(connection, ConfigurationManager.AppSettings["delete_customer"]); zetdeleteparameters(ref commando); customeradapter.deletecommand = commando; commando = createcommand(connection, ConfigurationManager.AppSettings["update_customer"]); zetupdateparameters(ref commando); customeradapter.updatecommand = commando; commando = createcommand(connection, ConfigurationManager.AppSettings["insert_customer"]); zetinsertparameters(ref commando); customeradapter.insertcommand = commando; - private void zetinsertparameters(ref DbCommand commando) DbParameter param = commando.createparameter(); setcolumnenversion(ref param, "@customernumber", DbType.Int32, "customernumber", DataRowVersion.Current); commando.parameters.add(param); param = commando.createparameter(); setcolumnenversion(ref param, "@customername", DbType.String, "customername", DataRowVersion.Current); commando.parameters.add(param); etc... - private void zetupdateparameters(ref DbCommand commando) DbParameter param = commando.createparameter(); setcolumnenversion(ref param, "@customernumber", DbType.Int32, "customernumber", DataRowVersion.Original); commando.parameters.add(param); etc... - private void zetdeleteparameters(ref DbCommand commando) DbParameter customernumber = commando.createparameter(); setcolumnenversion(ref customernumber, "@customernumber", DbType.Int32, "customernumber", DataRowVersion.Original); commando.parameters.add(customernumber);

- public DataSet getcustomers() DataSet customers = new DataSet(); customeradapter.fill(customers,"customers"); return customers; - public void updatecustomers(dataset customers) customeradapter.update(customers,"customers"); Stored Procedures Een stored procedure is een functie of procedure die bewaard wordt in een gegevensbank en die door clientapplicaties kan opgeroepen worden. Deze functie of procedure haalt informatie op uit de gegevensbank of manipuleert zijn data. stored procedure eerst toevoegen in de mysql terminal ConnectionStringSettings connstring = ConfigurationManager.ConnectionStrings["classicmodels"]; DbProviderFactory factory = DbProviderFactories.GetFactory(connString.ProviderName); DbConnection connection = factory.createconnection(); connection.connectionstring = connstring.connectionstring; DataSet ds = new DataSet(); connection.open(); try Console.WriteLine("Blah blah"); DbCommand command = connection.createcommand(); command.commandtext = ConfigurationManager.AppSettings["getAmount"]; command.commandtype = CommandType.StoredProcedure; DbParameter param = factory.createparameter(); param.dbtype = DbType.Int32; param.parametername = "code"; param.value = 114; command.parameters.add(param); DbParameter param2 = factory.createparameter(); param2.dbtype = DbType.Double; param2.parametername = "totaal"; param2.direction = ParameterDirection.Output; command.parameters.add(param2); command.executenonquery(); Console.WriteLine(command.Parameters["totaal"].Value);