C#连接MySQL进行操作的方法
由于需要实现以下功能:
网关通过串口发送数据给PC机,PC机收集数据并解析保存到MySQL中,然后JSP页面读取MySQL中的数据并显示。
所以利用C#连接MySQL数据成为了必须要经过的过程,在此给予详细的说明。
1、下载需要的文件MySQLDriverCS,下载地址为:http://sourceforge.net/projects/mysqldrivercs
2、安装文件:MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.exe,在安装过程中也许会提示一个错误,禁止写一个dll文件,你直接忽略就可以了。
3、将安装文件下的MySQLDriver.dll文件添加到C#项目的引用中。
4、然后写公共处理类如下:
(1) 首先得引用命名空间:
using MySQLDriverCS;
using System.Data;
using System.Data.Odbc;
(2) 写公共处理类
public class SQLHelper
{
MySQLConnection conn = null;
MySQLCommand commn = null;
public MySQLConnection GetConnect()
{
conn = new MySQLConnection(new MySQLConnectionString("localhost", "wwater", "root", "123").AsString);
return conn;
}
public int RunMySQL(string sql)
{
int count = 0;
try
{
conn = GetConnect();
conn.Open();
commn = new MySQLCommand(sql, conn);
count = commn.ExecuteNonQuery();
return count;
}
catch (Exception ex)
{
throw;
}
finally
{
conn.Close();
}
}
}
(3) 在实际过程中进行引用RunMySQL方法即可插入数据了。
相关文档:
截取province字符串中第一个<br>前的字符串~!
update lcjd
set `province` = substring_index( `province` , '<br>', '1' );
在需要添加‘0’的位置添加一个‘0’
update lcjd
set lc_name2 = concat('0', lc_name2)
WHERE length(lc_name2) = 3
http://www.sqlstudy.com/s ......
SqLite.net的dll为System.Data.SQLite.dll,这种dll分为32位、64位和适用于compactframework三种,在引用时要注意,选择正确的dll。
将要保存图片的字段类型设为blob。代码如下:
private void savePicture()
{
using (SQLiteConnection cnn = new SQLiteConnection(dbPath))
......
卸载mysql
1、查找以前是否装有mysql
命令:rpm -qa|grep -i mysql
可以看到mysql的两个包:
mysql-4.1.12-3.RHEL4.1
mysqlclient10-3.23.58-4.RHEL4.1
2、删除mysql
删除命令:rpm -e --nodeps 包名
( rpm -ev mysql-4.1.12-3.RHEL4.1 )
3、删除老版本mysql的开发头文件和库
命令:rm -fr /usr/lib/mysql
r ......
1、提交表单Javascript验证
<form action="" method="post" name="myform" onsubmit="return CheckPost();">
SCRIPT language=javascript>
function CheckPost()
{
if (myform.user.value=="")
{
alert("请填写用户");
myform.user.focus();
return f ......
//主键
alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);
//增加一个新列
alter table t2 add d timestamp;
alter table infos add ex tinyint not null default '0';
//删除列
alter table t2 drop column c;
//重命名列
......