C# 数据库操作类(存储过程)及调用方法
Int32 Size, ParameterDirection Direction, object Value)
{
SqlParameter param;
if(Size > 0)
param = new SqlParameter(ParamName, DbType, Size);
else
param = new SqlParameter(ParamName, DbType);
param.Direction = Direction;
if (!(Direction == ParameterDirection.Output && Value == null))
param.Value = Value;
return param;
}
#endregion
#region 将DataReader 转为 DataTable
/// <summary>
/// 将DataReader 转为 DataTable
/// </summary>
/// <param name="DataReader">DataReader</param>
public static DataTable ConvertDataReaderToDataTable(SqlDataReader reader)
{
try
{
DataTable objDataTable = new DataTable();
int intFieldCount = reader.FieldCount;
for (int intCounter = 0; intCounter < intFieldCount; ++intCounter)
{
objDataTable.Columns.Add(reader.GetName(intCounter), reader.GetFieldType(intCounter));
}
objDataTable.BeginLoadData();
object[] objValues = new object[intFieldCount];
while (reader.Read())
{
reader.GetValues(objValues);
objDataTable.LoadDataRow(objValues, true);
}
reader.Close();
objDataTable.EndLoadData();
return objDataTable;
}
catch(Exception ex)
{
throw new Exception("转换DataReader为DataTable出错!",ex);
}
}
#endregion
#region 数字判定
/// <summary>
/// 数字判定
/// </summary>
/// <param name="str">字符串参数</param>
public static bool IsNumber(String strNumber)
{
Regex objNotNumberPattern = new Regex("[^0-9.-]");
Regex objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9]*");
Regex objTwoMinusPattern = new Regex("[0-9]*[-][0-9]*[-][0-9]*");
String strValidRealPattern = "^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
String strValidIntegerPattern = "^([-]|[0-9])[0-9]*$";
Regex objNumberPattern = new Regex("(" + strValidRealPattern + ")|(" + strValidIntegerPattern + ")");
return !objNotNumberPattern.IsMatch(strNumber) &&
!objTwoDotPattern.IsMatch(strNumber) &&
!objTwoMinusPattern.IsMatch(strNumber) &&
objNumberPattern.IsMatch(strNumber);
}
#endregion
}
}
///////////使用
SqlDataReader dataReader = null;
Database data = new Database();
SqlParameter[] prams = {
data.MakeInParam("@LinkID",SqlDbType.Int, 4, LinkID),
};
try
{
data.RunProc("存储过程", prams, out dataReader);
return dataReader;
}
catch (Exception ex)
{
throw new Exception("友情链接读取出错!", ex);
}
C# 数据库操作类(存储过程)及调用方法_计算机软件及应用_IT/计算机_专业资料。C# 数据库操作类(存储过程)及调用方法 ///数据访问类 using System; using System...
c#使用数据库存储过程的基本方法 2007-05-28 16:58 440人阅读 评论(0) 收藏...更重要的是,存储过程可以写入多条的语句,对于需要得到数据库操作结果的模块非常...
而调用存储过程实现数据库操作是很多程序员使用的方法,而且大多数的程序员都是能 使用存储过程就使用存储过程,很少直接使用 SQL 语句,所以存储过程在数据库编程中是...
最近做一个项目,为了提高数据库安全性,客户要求所有数据库操作都要放在存储过程...使用ASP.NET访问Oracle数据库的方法 http://www.weiw.com/article/list.asp?...
背景 我们在使用 SQL Server 存储过程时,最常做的工作就是从数据库中读取或...这 样通过调用 ExecuteNonQuery()方法就可以执行更新操作了。再接下来就是关闭连...
用C调用mysql数据库的存... 2页 7下载券 C#...设置好 ColumnName ,再设置此列的表达式, DataColumn...存储过程调用如下: ---...
该类就运用存储过程对程序进行增加用户的 操作; 示例代码: AddUserService.cs ... 用C调用mysql数据库的存... 2页 7下载券 Java程序如何调用Oracle... 暂无...
使用SqlDataAdapter将自动完成数据库的打开和关闭过程,并执行相应t-sql语句或存储过程 //如果存储过程只是执行相关操作,如级联删除或更新,使用SqlCommand的execute方法...
ORACLE存储过程简析及C#调用_IT/计算机_专业资料。...规范的样式类似于 C 或 C++ 头文件。 --创建一... Oracle数据库简单操作类,对一些原有的方法有针对性...
(@v_begin_day, 'C', DAY(@v_begin_day) )...调用存储过程 CallProcedure(conn); // 关闭数据库... 方法,表明本次操作,不是一个查询的操作。...
热门文档