问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

asp.net调用mysql存储过程,插入表中字段类型为Text的数据

发布网友 发布时间:2022-05-07 03:50

我来回答

3个回答

懂视网 时间:2022-05-07 08:12

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:


  

热心网友 时间:2022-05-07 05:20

parameterprgoodsExplain.Value = goodsExplain; 后面加这句试试看
parameterprgoodsExplain.Direction = ParameterDirection.Input;
-------------------------------------------------------------
汗,这个原因啊,学习了

热心网友 时间:2022-05-07 06:38

这样搭配效率不好,最好是别这样。我劝你拉。.
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
人教版小学英语课本哪里能下载到MP3 小学英语同步听力音频去哪里找 去陆丰旅行,要提前做好什么准备? 请教高手:苹果6s能不能安装两个微信?谢谢指点! 对于一个在女性内衣店工作的男性,你们怎么看待 ...湖是世界最深和蓄水量最大的咸水湖 B.死海是世界最低点 C.马来群 ... ...世界最大的湖泊___世界上人口最多的国家___世界上面积最大... 世界最深和蓄水量最大的湖是什么?世界最低点是哪?世界面积最大的高原... 尚赫净水器滤芯 如何清洗尚赫 电脑怎么用万能钥匙蹭网 麻烦大家解答一下,这是固态硬盘坏了还是机械硬盘坏了? “多干点活,我妈想看未来儿媳贤不贤惠”,男友这样的做法你怎样看? 董鄂妃也有婆媳烦恼,为何孝庄太后不喜欢貌美温柔的儿媳董鄂妃呢? 司马炎皇后贤良淑德,为何会被“丑儿媳”贾南风赶尽杀绝? 司马炎皇后贤良淑德,为何会被“丑儿媳”贾南风活活饿死呢? 赞美媳妇的诗句 iphone11怎么自动化中无法播报声音 祝福儿子媳妇生日祝福语 SDN WAN中文名称? 亲 能帮我查一下这个序列号的信息吗 谢谢了 CCQGJSUSDNQW 在Java中怎么循环打印出<LIST>的各属性的值?我在JSP中用下列可以,在Java中该如何打印? 建行查询交易地点为SDNX是什么意思? 冰箱价格清单 非sdn名单有几种 重庆的54所院校是哪些? 重庆一共有几所中学,分别是什么学校?地址在哪? 硬币,硬币上有EN KRONA的字样.还有皇冠和貌似欧洲人的头像是哪国硬币? windows10wifi怎么连接 手机注册拳头账号看不懂验证码图片英文? 电脑上连接Wi-Fi可以用万能钥匙吗?不知道密码想蹭网 你做的薯条发软不脆?秘诀在这 如何提升招商银行信用卡额度 招商银行信用卡怎么提高额度 保单现金价值 1000 本省省控线是什么意思 省控线是按照户口本所在地还是按照高中所在省 户籍在黑龙江,学籍山东高考在山东没过省控线可以按户籍省控线报学校吗?? 省控线是针对本地考生的最低分还是外地考生啊?如果我要报外省学校的话,应该看当地此院校省控线还是平 省控线是指哪个省的啊 省控线 是什么意思? 只要过了省控线就可以考上吗 省控线是不是只对本省 mysql存储过程怎么建?asp.net要调用一个存储过程,我在mysql查询编辑器里写得。 报了图片中的错误。 table中的行高调整 css,table如何平均行高? table怎样控制行高,就是td里面每一排文字的高度 怎么可以得到一个table表单中每行的高度? 如何用jquery在页面控制table的行高?就是页面载入表格数据候,想在页... 设置Table的列宽问题和行高问题 html当table高度固定的时候如何设置每一行的高度