Click here to Skip to main content
15,879,535 members
Articles / Web Development / HTML

MySQL 5 C# sample code using ObjectDataSources

Rate me:
Please Sign up or sign in to vote.
4.33/5 (27 votes)
15 May 2006BSD2 min read 352.5K   5.4K   118  
A simple example using MySQL 5 and stored procedures with ObjectDataSources and Generics, in ASP.NET 2.0.
1) You must have MySQL 5 up and running

2) You must install "MySQL Connector/Net 1.0" from: http://dev.mysql.com/downloads/connector/net/1.0.html

3) Create a MySQL 5 database named "Test"

4)  Create a table in that database called Message:

CREATE TABLE test.message (
Entry_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
Name VARCHAR(45),
Email VARCHAR(45),
Message VARCHAR(200),
PRIMARY KEY (Entry_ID)
)
AUTO_INCREMENT=32
CHARACTER SET latin1 COLLATE latin1_swedish_ci;

5) Create these MySQL stored procedures:

PROCEDURE `test`.`DeleteMessage`(IN param1 INT)
BEGIN
Delete From test.message
WHERE Entry_ID = param1;
END
PROCEDURE `test`.`InsertMessage`(IN param1 VARCHAR(50), IN param2 VARCHAR(50), IN param3 VARCHAR(200))
BEGIN
INSERT INTO message(Name, Email, Message)
VALUES(param1,param2,param3);
END
PROCEDURE `test`.`ShowAll`()
BEGIN
SELECT 
� message.Entry_ID, 
� message.Name, 
� message.Email, 
� message.Message
FROM
� test.message;
END
PROCEDURE `test`.`UpdateMessage`(IN paramkey INT, IN param1 VARCHAR(50), IN param2 VARCHAR(50), IN param3 VARCHAR(200))
BEGIN
UPDATE��� message
SET������������� Name = param1, Email = param2, Message = param3
WHERE���� (message.Entry_ID = paramkey);
END

6) Unzip the "MySQL" and configure IIS to point to it. MAKE SURE YOU CONFIGURE THE WEBSERVER TO USE ASP.NET 2.0

7) Open "web.config" and change the line:
		<add name="MySQLConnectionString" connectionString="server=localhost; user id=myuser; password=mypass; database=test; pooling=false;" providerName="MySql.Data.MySqlClient"/>
to connect to your MySQL database

8) Browse to the default.aspx page and the sample should work.

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Software Developer (Senior) http://ADefWebserver.com
United States United States
Michael Washington is a Microsoft MVP. He is a ASP.NET and
C# programmer.
He is the founder of
AiHelpWebsite.com,
LightSwitchHelpWebsite.com, and
HoloLensHelpWebsite.com.

He has a son, Zachary and resides in Los Angeles with his wife Valerie.

He is the Author of:

Comments and Discussions