using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Text.RegularExpressions;
using System.Data.OleDb;
namespace DBConnect
{
/// <summary>
/// DBConnect 的摘要说明。
/// </summary>
public class DBConnection
{
private OleDbConnection objConnection; public DBConnection()
{
//
// TODO: 在此处添加构造函数逻辑
//
objConnection=new OleDbConnection(ConfigurationSettings.AppSettings["netlx"]);
//objConnection=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("exexchange.mdb")); //Access :Provider=Microsoft.Jet.OLEDB.4.0; Data Source=test
//Oracle: Provider=OraOLEDB.Oracle.1;Persist Security Info=True;User ID=huoche;Password=huoche;Data Source=huoche
}
public void Open()
{
} public void ExecNonQuery(string strSQL) //执行不返回结果
{
objConnection.Open();
OleDbCommand objCommand = new OleDbCommand(strSQL, objConnection);
objCommand.ExecuteNonQuery();
objConnection.Close();
} public DataSet CreateDataSet(string strSQL, string strTableName) //返回结果 select
{
objConnection.Open();
OleDbDataAdapter MyAdapter = new OleDbDataAdapter(strSQL,objConnection);
DataSet ds = new DataSet();
MyAdapter.Fill(ds,strTableName);
objConnection.Close(); return ds;
} public int Lenx(string str) //变量长度
{
int theLen = 0;
char[] str2=str.ToCharArray();
foreach (char b in str2)
{
if ((short)b<0||(short)b>255)
{
theLen=theLen+2;
}
else
{
theLen=theLen+1;
}
}
return(theLen);
} public string CheckInvalidChar(string strInput) //替换'
{
string strTemp = strInput; strTemp = strTemp.Replace("'","''");
//strTemp = Server.HtmlEncode(strTemp);
return strTemp;
} public string EncryptPasswd(string str)//用于mD5加密
{
string passwd2;
passwd2 = FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5");
return passwd2;
}
public bool isint(string num) //是否为整数
{
Regex reg=new Regex("^[0-9]*$");
return reg.IsMatch(num);
}
public bool isnum(string num) //是否为小数
{
Regex reg=new Regex("^([0-9]*).([0-9]*)$");
return reg.IsMatch(num);
}
public bool isdate(string num) //是否为合法日期
{
Regex reg=new Regex(@"^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3-9]|1[0-2])[\/\-\.](?:29|30))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3,5,7,8]|1[02])[\/\-\.]31)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:16|[2468][048]|[3579][26])00[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1-9]|1[0-2])[\/\-\.](?:0?[1-9]|1\d|2[0-8]))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$");
return reg.IsMatch(num);
}
public string filestype(string files1) //带点的文件扩展名
{
return files1.Substring(files1.LastIndexOf('.'),files1.Length-files1.LastIndexOf('.'));
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Text.RegularExpressions;
using System.Data.OleDb;
namespace DBConnect
{
/// <summary>
/// DBConnect 的摘要说明。
/// </summary>
public class DBConnection
{
private OleDbConnection objConnection; public DBConnection()
{
//
// TODO: 在此处添加构造函数逻辑
//
objConnection=new OleDbConnection(ConfigurationSettings.AppSettings["netlx"]);
//objConnection=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("exexchange.mdb")); //Access :Provider=Microsoft.Jet.OLEDB.4.0; Data Source=test
//Oracle: Provider=OraOLEDB.Oracle.1;Persist Security Info=True;User ID=huoche;Password=huoche;Data Source=huoche
}
public void Open()
{
} public void ExecNonQuery(string strSQL) //执行不返回结果
{
objConnection.Open();
OleDbCommand objCommand = new OleDbCommand(strSQL, objConnection);
objCommand.ExecuteNonQuery();
objConnection.Close();
} public DataSet CreateDataSet(string strSQL, string strTableName) //返回结果 select
{
objConnection.Open();
OleDbDataAdapter MyAdapter = new OleDbDataAdapter(strSQL,objConnection);
DataSet ds = new DataSet();
MyAdapter.Fill(ds,strTableName);
objConnection.Close(); return ds;
} public int Lenx(string str) //变量长度
{
int theLen = 0;
char[] str2=str.ToCharArray();
foreach (char b in str2)
{
if ((short)b<0||(short)b>255)
{
theLen=theLen+2;
}
else
{
theLen=theLen+1;
}
}
return(theLen);
} public string CheckInvalidChar(string strInput) //替换'
{
string strTemp = strInput; strTemp = strTemp.Replace("'","''");
//strTemp = Server.HtmlEncode(strTemp);
return strTemp;
} public string EncryptPasswd(string str)//用于mD5加密
{
string passwd2;
passwd2 = FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5");
return passwd2;
}
public bool isint(string num) //是否为整数
{
Regex reg=new Regex("^[0-9]*$");
return reg.IsMatch(num);
}
public bool isnum(string num) //是否为小数
{
Regex reg=new Regex("^([0-9]*).([0-9]*)$");
return reg.IsMatch(num);
}
public bool isdate(string num) //是否为合法日期
{
Regex reg=new Regex(@"^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3-9]|1[0-2])[\/\-\.](?:29|30))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3,5,7,8]|1[02])[\/\-\.]31)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:16|[2468][048]|[3579][26])00[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1-9]|1[0-2])[\/\-\.](?:0?[1-9]|1\d|2[0-8]))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$");
return reg.IsMatch(num);
}
public string filestype(string files1) //带点的文件扩展名
{
return files1.Substring(files1.LastIndexOf('.'),files1.Length-files1.LastIndexOf('.'));
}
}
}
解决方案 »
- webservice报404错误
- IIS url路径问题会自动添加类似(S(ju1gvv550o5dwd55swtm0s45))的字符
- vs2005 是否支持Asp.Net Ajax客户端JavaScript智能提示功能?
- 用AspNetPager怎么实现DataList分页的。
- 用C#怎样把一张图片平均分割成多张图片
- 求助:附件上传保存在一个文件夹下面,请问在程序里删除一条记录时连同这个文件夹下面的相应的附件也被删除,怎么做??
- .net 动态生成网页
- 继承类的问题
- 数据库问题
- 如何在Page_load()中用C#来显示系统日期?(在线等待)
- 好像和codebehind 有关的问题,各位高手进来帮帮忙吧。。。
- 急。怎样把页面中dategrid里面的控件Disabled或者Enabled?中午揭帖。。。。急
替換你的聯結字符串就ok。
替換你的聯結字符串就ok。完全正确