易截截图软件、单文件、免安装、纯绿色、仅160KB

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方法即可插入数据了。  


相关文档:

C#处理oracle lob的例子

  protected void BindData1()
    {
        OracleConnection orcn = new OracleConnection("User ID=wesoftwcp; Password=wesoft; Data Source=oradb");
        orcn.Open();
      &nb ......

Java 把文本中的数据插入到MySql数据库

一共有三个类:WriteFile ; ReadFile ; InsertDB ;
//WriteFile.java
//用于将信息写入文本文件
package org.mb.insertfromfile;
import java.io.*;
public class WriteFile{
private int count = 0 ;
public int getCount() {
return count;
}
public void setCount(int count) {
this.cou ......

mysql alter 语句用法,添加、修改、删除字段等


//主键
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;
//重命名列
......

MySQL的datetime设置当前时间为默认值


MySQL的datetime设置当前时间为默认值 
由于MySQL目前字段的默认值不支持函数,所以用
create_time datetime default now()
的形式设置默认值是不可能的。
代替的方案是使用TIMESTAMP类型代替DATETIME类型。
CURRENT_TIMESTAMP :当我更新这条记录的时候,这条记录的这个字段不会改变

CURRENT_TIMESTAMP O ......

用python连接mysql数据库


#
-*- encoding: gb2312 -*-
import
os, sys, string
import
MySQLdb
#
连接数据库
try
:
conn
=
MySQLdb.connect(host
=
'
localhost
'
,user
=
'
root
'
,passwd
=
'
xxxx
'
,db
=
'
test1
'
)
except
Exception, e:
print
e
sys.exit()
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号