搜尋
首頁資料庫mysql教程 老外的.net与mysql存储过程编程
老外的.net与mysql存储过程编程Jun 07, 2016 pm 02:52 PM
.netmysqlthe儲存程式設計過程

Go to the MySQL website, download and install “Current Release (recommended)”. Download and install: MySQL Administrator (to administer your MySQL server, the first download just installs only the server). Download and install: Connector

  Go to the MySQL website, download and install “Current Release (recommended)”.
Download and install: MySQL Administrator (to administer your MySQL server, the first download just installs only the server).
Download and install: Connector/Net 1.0 (you need this to get your ASP.NET pages to talk to your MySQL server).
You can also download: MySQL Query Browser – (a graphical client to work with your MySQL databases and run queries).
Read and follow this guide: A Step-by-Step Guide to Using MySQL with ASP.NET.
To install the code:
You must have MySQL 5 up and running.
Install MySQL Connector/Net 1.0.
Create a MySQL 5 database named Test.
Create a table in that database called Message:
CREATE TABLE ssage (    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;
Create these four MySQL stored procedures in the Test database:
PROCEDURE `test`.`DeleteMessage`(IN param1 INT)BEGINDelete From ssageWHERE Entry_ID = param1;END
PROCEDURE `test`.`InsertMessage`(IN param1 VARCHAR(50), IN param2     VARCHAR(50), IN param3 VARCHAR(200))BEGININSERT INTO message(Name, Email, Message)VALUES(param1,param2,param3);END
PROCEDURE `test`.`ShowAll`()BEGINSELECT   message.Entry_ID,  message.Name,   message.Email,   message.MessageFROM  ssage;END
PROCEDURE `test`.`UpdateMessage`(IN paramkey INT, IN param1 VARCHAR(50),     IN param2 VARCHAR(50), IN param3 VARCHAR(200))BEGINUPDATE    messageSET              Name = param1, Email = param2, Message = param3WHERE     (message.Entry_ID = paramkey);END
Unzip "MySQL" and configure IIS to point to it. Make sure you configure the web server to use ASP.NET 2.0.
Open "nfig" and change the line:

  using System;using System.Collections.Generic;using System.Data;using MySql.Data.MySqlClient;using System.Configuration;using System.ComponentModel;[DataObject(true)]public static class MessagesDB{    private static string GetConnectionString()    {        return ConfigurationManager.ConnectionStrings        ["MySQLConnectionString"].ConnectionString;    }    [DataObjectMethod(DataObjectMethodType.Select)]    public static List GetMessages()    {        MySqlCommand cmd = new MySqlCommand("ShowAll",                            new MySqlConnection(GetConnectionString()));        cmd.CommandType = CommandType.StoredProcedure;        cmd.Connection.Open();        MySqlDataReader dr =            cmd.ExecuteReader(CommandBehavior.CloseConnection);        List MessageItemlist = new List();        while (dr.Read())        {            MessageItem MessageItem = new MessageItem();            MessageItem.Entry_ID = Convert.ToInt32(dr["Entry_ID"]);            MessageItem.Message = Convert.ToString(dr["Message"]);            MessageItem.Name = Convert.ToString(dr["Name"]);            MessageItem.Email = Convert.ToString(dr["Email"]);            MessageItemlist.Add(MessageItem);        }        dr.Close();        return MessageItemlist;    }    [DataObjectMethod(DataObjectMethodType.Insert)]    public static void InsertMessage(MessageItem MessageItem)    {        MySqlCommand cmd = new MySqlCommand("InsertMessage",                            new MySqlConnection(GetConnectionString()));        cmd.CommandType = CommandType.StoredProcedure;        cmd.Parameters.Add(new MySqlParameter("param1", MessageItem.Name));        cmd.Parameters.Add(new MySqlParameter("param2", MessageItem.Email));        cmd.Parameters.Add(new MySqlParameter("param3", MessageItem.Message));        cmd.Connection.Open();        cmd.ExecuteNonQuery();        cmd.Connection.Close();    }    [DataObjectMethod(DataObjectMethodType.Update)]    public static int UpdateMessage(MessageItem MessageItem)    {        MySqlCommand cmd = new MySqlCommand("UpdateMessage",                            new MySqlConnection(GetConnectionString()));        cmd.CommandType = CommandType.StoredProcedure;        cmd.Parameters.Add(new MySqlParameter("paramkey", MessageItem.Entry_ID));        cmd.Parameters.Add(new MySqlParameter("param1", MessageItem.Name));        cmd.Parameters.Add(new MySqlParameter("param2", MessageItem.Email));        cmd.Parameters.Add(new MySqlParameter("param3", MessageItem.Message));        cmd.Connection.Open();        int i = cmd.ExecuteNonQuery();        cmd.Connection.Close();        return i;    }    [DataObjectMethod(DataObjectMethodType.Delete)]    public static int DeleteMessage(MessageItem MessageItem)    {        MySqlCommand cmd = new MySqlCommand("DeleteMessage",                 new MySqlConnection(GetConnectionString()));        cmd.CommandType = CommandType.StoredProcedure;        cmd.Parameters.Add(new MySqlParameter("param1", MessageItem.Entry_ID));        cmd.Connection.Open();        int i = cmd.ExecuteNonQuery();        cmd.Connection.Close();        return i;    }
the class above uses the class "MessageItem" to pass the parameters to and from the ObjectDataSource control:

  using System;public class MessageItem{    int _Entry_ID;    string _Message;    string _Name;    string _Email;    public MessageItem()    {    }    public int Entry_ID    {        get        {        return _Entry_ID;        }        set        {        _Entry_ID = value;        }    }    public string Message    {        get        {            return _Message;        }        set        {            _Message = value;        }    }    public string Name    {        get        {            return _Name;        }        set        {            _Name = value;        }    }    public string Email    {        get        {            return _Email;        }        set        {            _Email = value;        }    }}
this is the .aspx file that contains the ObjectDataSource control as well as a GridView for editing data and a DetailsView for inserting a record:


  

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
mysql怎么替换换行符mysql怎么替换换行符Apr 18, 2022 pm 03:14 PM

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql的msi与zip版本有什么区别mysql的msi与zip版本有什么区别May 16, 2022 pm 04:33 PM

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

C#的就业前景如何C#的就业前景如何Oct 19, 2023 am 11:02 AM

无论您是初学者还是有经验的专业人士,掌握C#将为您的职业发展铺平道路。

分享几个.NET开源的AI和LLM相关项目框架分享几个.NET开源的AI和LLM相关项目框架May 06, 2024 pm 04:43 PM

当今人工智能(AI)技术的发展如火如荼,它们在各个领域都展现出了巨大的潜力和影响力。今天大姚给大家分享4个.NET开源的AI模型LLM相关的项目框架,希望能为大家提供一些参考。https://github.com/YSGStudyHards/DotNetGuide/blob/main/docs/DotNet/DotNetProjectPicks.mdSemanticKernelSemanticKernel是一种开源的软件开发工具包(SDK),旨在将大型语言模型(LLM)如OpenAI、Azure

mysql怎么将varchar转换为int类型mysql怎么将varchar转换为int类型May 12, 2022 pm 04:51 PM

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

MySQL复制技术之异步复制和半同步复制MySQL复制技术之异步复制和半同步复制Apr 25, 2022 pm 07:21 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

带你把MySQL索引吃透了带你把MySQL索引吃透了Apr 22, 2022 am 11:48 AM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

mysql怎么判断是否是数字类型mysql怎么判断是否是数字类型May 16, 2022 am 10:09 AM

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前By尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器