SQL commands from C# and ASP.net

Slides:



Advertisements
Similar presentations
Adding a database to web service Add a database – Service->Add new item->SQL server database Add table to database – Server explorer->tables->Add new table.
Advertisements

ADO. NET. What is “ADO.Net”? ADO.Net is a new object model for dealing with databases in.Net. Although some of the concepts are similar to the classical.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
In C# program Before you can start using the ODBC class definitions, you will need to include the right module. using System.Data.Odbc; // ODBC definitions.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
Chapter 9 Using the SqlDataSource Control. References aspx.
ASP.NET Part 3 Instructor: Charles Moen CSCI/CINF 4230.
SQL Azure Database Windows Azure SQL Database is a feature-rich, fully managed relational database service that offers a highly productive experience,
11 Updating a Database Table Textbook Chapter 14.
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
Intro to C#.net and EF Ilan Shimshoni. The Three Faces of ADO.NET The connected layer – Directly connecting to the DB The disconnected layer – Using datasets.
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 4. 2 Overview Data Binding Data Providers Data Connection Data Manipulations.
Accessing SQL Server and OLE DB from.NET Svetlin Nakov Telerik Corporation
Neal Stublen Populating a Database  SQLExpress should be installed with Visual Studio  The book provides a.sql file for populating.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
MySQL Connection using ADO.Net Connecting to MySQL from.NET Languages.
11 Using ADO.NET II Textbook Chapter Getting Started Last class we started a simple example of using ADO.NET operations to access the Addresses.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
TOP10 DEV SKILLS TO MAKE YOUR DBA HAPPY Kevin Kline Director of Engineering Services, SQL Sentry SQL Server MVP since 2004 Twitter, FB, LI: KEKline Blog:
ASP.NET Rina Zviel-Girshin Lecture 5
Neal Stublen Tonight’s Agenda  Database Errors  Parameterized queries  ToolStrip control  Master-detail relationships  Custom.
ADO.NET Objects – Data Providers Dr. Ron Eaglin. Requirements Visual Studio 2005 Microsoft SQL Server 2000 or 2005 –Adventure Works Database Installed.
ADO.NET connections1 Connecting to SQL Server and Oracle.
DAT356 Hackers Paradise SQL Injection Attacks Doug Seven, Microsoft MVP Cofounder of SqlJunkies.com
Command Object’s ExecuteNonQuery Method ISYS 512.
1.NET Language Integrated Query Yishai Zaltzberg.
1 11/10/05CS360 Windows Programming ADO.NET. 2 11/10/05CS360 Windows Programming ADO.NET  Behind every great application is a database manager o Amazon.
More ASP.NET Database In a properly organized application, your data access code is never embedded directly in the code-behind for a page. Instead, it’s.
1 Avoiding Hacker Attacks. 2 Objectives You will be able to Avoid certain hacker attacks and crashes due to bad inputs from users.
Distributed Database Systems INF413. ADO.NET is a set of classes that comes with the Microsoft.NET framework to facilitate data access from managed languages.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
HNDIT Rapid Application Development
Coding ADO.NET Objects: Connection, Command, DataReader.
1 Low Level ADO.NET Operations II Microsoft Visual C# 2008 Step by Step Chapter 25.
Using Database: A very, very short introduction..
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 The SqlCommand Object ADO.NET - Lesson 03  Training time: 15 minutes  Author:
Introduction to Database C# MySQL onnect-C-to-MySQL 1.
Рис.1. Схема взаємодії компонентів ASP.NET MVC Контролер (controller) - клас, з якого починається робота програми. Забезпечує зв'язок між моделлю і представленням.
.NET Data Access and Manipulation
ELASTIC DATABASE CAPABILITIES WITH AZURE SQL DB Silvia Doomra Azure SQL DB Program Management.
C# MySQL onnect-C-to-MySQL 1.
Lecture Select Operation 2. Insert Operation 3. Update Operation 4. Delete Operation.
 ADO.NET is an object-oriented set of libraries that allows you to interact with data sources  Commonly, the data source is a database, but it could.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
ASP.NET Programming with C# and SQL Server First Edition
Introduction to ADO.NET
DB Apps Introduction Intro to ADO.NET SQL SoftUni Team DB Apps Intro
ADO.NET Fundamentals.
ADO.NET and Stored Procedures
How to Create Login Form using vb.net and SqlServer Database
Lecture 6 VB.Net SQL Server.
Overview of Data Access
Databases Intro (from Deitel)
How to use ADO.NET to write your own data access code
Unit 9.2 Database access from code Database Cycle Review
Overview of Data Access
ADO.Net and Stored Procedures
Session management.
An Introduction to Entity Framework
מתחברים למסד נתונים היכרות עם ADO.Net.
Stored Procedures
MySQL Connection using ADO.Net
E-commerce Applications Development
How to use ADO.NET to write your own data access code
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
ADO.NET Fundamentals.
Presentation transcript:

SQL commands from C# and ASP.net

SQL commands Microsoft’s database system is called “SQL Server” The most popular open source database is called “MySQL” SQL : Structured Query Language Select * From PlantData Where Collection = ‘Ivy‘ Select * From PlantData Where Location = ‘House10’ Lists all the database records that satisfy that criteria Select COUNT (DISTINCT ScientificName) FROM PlantData Counts the number of unique plant names therefore = number of plant types Returns a useful statistic

Question 1: How do you issue an SQL command from C#? It’s all about the connection string: string CONNECTION_STRING = "Data Source=MBUCKLEY16; Initial Catalog=BotanicalApp; Integrated Security=True"; string CONNECTION_STRING_LOCATIONS ="Data Source=MBUCKLEY16; Initial Catalog=Locations; Integrated Security=True"; string CONNECTION_STRING_COLLECTIONS ="Data Source=MBUCKLEY16; Initial Catalog=Collections; Integrated Security=True"; note: SERVER DATABASE

Issuing an SQL command with no reply string connectionString = GlobalVariables.CONNECTION_STRING; SqlConnection sqlConnection1 = new SqlConnection(connectionString); sqlConnection1.Open(); // SQL output SqlCommand cmd = new SqlCommand(); cmd.CommandText = "INSERT INTO PlantData( [ID], [CommonName]) VALUES (‘1258’, ‘Daisy’) " ; cmd.Connection = sqlConnection1; cmd.ExecuteNonQuery(); // executes the Command, expects no reply

Question 2: How do you get a reply? string connectionString = GlobalVariables.CONNECTION_STRING; String replyString = " "; SqlConnection sqlConnection1 = new SqlConnection(connectionString); sqlConnection1.Open(); // SQL output (query) SqlCommand cmd = new SqlCommand(); // SQL input (reader) SqlDataReader reader; IDataRecord readRecord = null; cmd.CommandText = "SELECT COUNT(DISTINCT ID) FROM PlantData"; cmd.Connection = sqlConnection1; reader = cmd.ExecuteReader(); // executes the command reads the reply readRecord = (IDataRecord)(reader); // places reply into a Data Record reader.Read(); // reads the Data Record replyString = String.Format("{0}", readRecord[0]); // convert ints to strings, nulls to "" if (String.Compare(replyString, "") != 0) // if not null { sqlConnection1.Close(); } // end if not blank else replyString = ("SQL Query Error"); } // end if

3. What to do with replyString? e.g. Stats.Text = replyString;

In Default.aspx.cs protected void Page_Load(object sender, EventArgs e) { UsefulFunctions SQLQuery = new UsefulFunctions(); Stats.Text = SQLQuery.SQLCommand("SELECT COUNT(DISTINCT ScientificName) FROM PlantData"); }