ASP.NET操作mysql数据库的实例(傻瓜都能看懂,已测试过)
来源:互联网 发布:淘宝店铺公告怎么修改 编辑:程序博客网 时间:2024/05/16 10:53
一、把MySql.Data.dll放到BIN目录下。
二、这是aspx.cs的全部源码,修改参数直接运行即可!
using MySql.Data.MySqlClient;using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Login : System.Web.UI.Page{ public static class MySqlHelper { public static int ExecuteNonQuery(string connectionString, CommandType commandtype, string commandText) { return ExecuteNonQuery(connectionString, commandtype, commandText, null); } public static int ExecuteNonQuery(string connectionString, CommandType commandtype, string commandText, params MySqlParameter[] commandParameters) { if (string.IsNullOrEmpty(connectionString)) { throw new Exception("connectionString exception"); } int result = 0; MySqlConnection con = null; try { using (con = new MySqlConnection(connectionString)) { con.Open(); MySqlCommand command = new MySqlCommand(commandText, con); command.CommandType = commandtype; result = command.ExecuteNonQuery(); } return result; } catch (Exception ex) { throw ex; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } } } protected void Page_Load(object sender, EventArgs e) { string connectionString = "server=localhost;uid=root;pwd=;database=zentaopro;"; LogManage_SqlDate.WriteLog("connectionString=:" + connectionString); string sql = "insert user(account) values('china2')"; MySqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, sql); Console.Read(); }}
在此基础上做了一个傻瓜版的,感谢此网址提供解决方案:http://www.cnblogs.com/zjypp/p/3327170.html
0 0
- ASP.NET操作mysql数据库的实例(傻瓜都能看懂,已测试过)
- 傻瓜都能看懂的栈与队列操作
- Handler过程剖析-傻瓜都能看懂的过程图
- 傻瓜都能看懂的高并发量服务器架构
- 连傻瓜都能看懂的基于代码注入的线程守护技术
- ASP.NET数据库操作实例
- VC6.0操作MYSQL数据库(已通过测试)
- 4j 都能看懂的例子
- 一般人都能看懂的git教程
- 任何人都能看懂的TensorFlow介绍
- 人人都能看懂的LSTM
- MYSQL数据库(已测试)
- agiledox产生的输出能直接被商业客户、分析师、测试人员都看懂!
- ASP.NET连接mysql 数据库实例
- ASP.NET连接mysql 数据库实例
- ASP.NET 操作MySQL数据库的方法说明
- JQuery easyui 在Asp.net环境的数据库操作测试(一)
- asp.net的Web应用报“超时时间已到。在操作完成之前超时时间已过或服务器未响应”问题的解决
- studio 如何添加 jar 和so文件
- C# 图片 旋转和翻转 RotateFlip
- js 获取url参数
- parseInt()和parseFloat()
- C++ operator new以及new operator的各种套路浅析
- ASP.NET操作mysql数据库的实例(傻瓜都能看懂,已测试过)
- JAVA实现页面置换算法(OPT,FIFO,LRU)
- 1.1.1 centos 下安装 zeroice
- 使用ListView
- 快速获取Qt编译Release程序所依赖的qt库
- LD_LIBRARY_PATH环境变量设置及Linux动态库查找方法
- iOS10 UI教程视图的生命周期
- jQuery选择器大全
- C#仿sqlServer中的checksum