下面的例子就是调用通用类的数据库 *** 作方法(数据库的链接与关闭都在通用类中),不懂得花可以发例子给你。using System;
using SystemCollectionsGeneric;
using SystemText;using TroubledTimesModels;
using SystemData;
using SystemDataSqlClient;namespace TroubledTimesDAL
{
/// <summary>
/// 官方活动信息数据访问类
/// </summary>
public static class FunctionsService
{
/// <summary>
/// 1根据不同情况查询活动信息
/// </summary>
/// <param name="type">活动类型</param>
/// <param name="state">设置状态</param>
/// <param name="name">活动名称</param>
/// <param name="flag">控制变量</param>
/// <returns>活动信息对象的集合</returns>
public static IList<Functions> GetAllFunctions(string type,string state,string name,int flag)
{
string sql = "Select from Functions where State =1";
if(type!="" && flag==1)
sql += " and FunState='" + type + "'";
else if (state != "" && flag == 2)
sql += " and SetState='" + state + "'";
else if (name!="" && flag==3)
sql += " and FunctionName like '%" + name + "%'";
else if (flag == 4)
sql += " and FunState='" + type + "' and SetState='" + state + "'";
else if (flag == 5)
sql += " and FunState='" + type + "' and FunctionName like '%" + name + "%'";
else if (flag == 6)
sql += " and SetState='" + state + "' and FunctionName like '%" + name + "%'";
else if (flag == 7)
sql += " and FunState='" + type + "' and SetState='" + state + "' and FunctionName like '%" + name + "%'";
sql += " order by FunNumber Desc";
IList<Functions> list = new List<Functions>();
try
{
// DataTable dt = DBHelperGetScalar("up_SelectFunctions");
DataTable dt = DBHelperGetDataTable(sql);
foreach (DataRow row in dtRows)
{
Functions function = new Functions();
functionFunctionName = (string)row["FunctionName"];
functionFId = (int)row["FId"];
functionFunctionUrl = (string)row["FunctionUrl"];
functionFunctionImg = (string)row["FunctionImg"];
functionFunctionContent = (string)row["FunctionContent"];
functionFunctionTime = (DateTime)row["FunctionTime"];
functionFunAdminUrl = (string)row["FunAdminUrl"];
functionFunState = (int)row["FunState"]; //--活动类型(游戏活动/官网活动,0:游戏)<后加>
functionSetState = (int)row["SetState"]; //--设置状态(设置中/预设置,0:预设置)<后加>
functionFunNumber = (int)row["FunNumber"]; //--活动支持率(仅官网)<后加>
functionState = (int)row["State"]; //--存贮状态(0/1)
listAdd(function);
}
return list;
}
catch (Exception ex)
{
ConsoleWriteLine(exMessage);
return null;
}
} /// <summary>
/// 2根据活动类型获取活动信息
/// </summary>
/// <param name="id">活动类型</param>
/// <returns>该活动类型的数量</returns>
public static int GetFunctionsByType(int type)
{
IList<Functions> list = new List<Functions>();
try
{
string sql = "select count() from Functions where SetState = 1 and FunState='" + type+ "'";
return DBHelperSanlar(sql); }
catch (Exception ex)
{
ConsoleWriteLine(exMessage);
return 0;
}
} /// <summary>
/// 3根据活动ID修改活动信息
/// </summary>
/// <param name="f">活动信息类对象</param>
/// <returns>数据库中受影响的行数</returns>
public static int ModifyFunctionsById(Functions f)
{
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@FId",fFId),
new SqlParameter("@FunctionName",fFunctionName),
new SqlParameter("@FunctionUrl",fFunctionUrl),
new SqlParameter("@FunctionImg",fFunctionImg),
new SqlParameter("@FunctionContent",fFunctionContent),
new SqlParameter("@FunctionTime",fFunctionTime),
new SqlParameter("@functionFunAdminUrl",fFunAdminUrl),
new SqlParameter("@FunState",fFunState),
new SqlParameter("@FunNumber",fFunNumber),
new SqlParameter("@SetState",fSetState),
new SqlParameter("@State",fState)
};
return DBHelperExecuteProc("up_AmendFunctions", para);
}
catch (Exception ex)
{
ConsoleWriteLine(exMessage);
return 0;
}
} /// <summary>
/// 4添加活动信息
/// </summary>
/// <param name="f">活动信息类对象</param>
/// <returns>数据库中受影响的行数</returns>
public static int AddFunctions(Functions f)
{
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@FunctionName",fFunctionName),
new SqlParameter("@FunctionUrl",fFunctionUrl),
new SqlParameter("@FunctionImg",fFunctionImg),
new SqlParameter("@FunctionContent",fFunctionContent),
new SqlParameter("@FunctionTime",fFunctionTime),
new SqlParameter("@FunAdminUrl",fFunAdminUrl),
new SqlParameter("@FunState",fFunState),
new SqlParameter("@FunNumber",fFunNumber),
new SqlParameter("@SetState",fSetState),
new SqlParameter("@State",fState) };
return DBHelperExecuteProc("up_AddFunctions", para);
}
catch (Exception ex)
{
ConsoleWriteLine(exMessage);
return 0;
} }
/// <summary>
/// 5、根据id批量删除活动信息(修改)
/// </summary>
/// <param name="id">活动信息id</param>
/// <returns>返回受影响的行数</returns>
public static int DeleteFunById(string ids)
{
//string sql = "update Functions set State = 0 where FId in('"+ids+"')";
string sql = "update Functions set State = 0 where FId ='" + ids + "'";
try
{
return DBHelperExecuteCommand(sql);
}
catch(Exception ex)
{
throw ex;
}
}
/// <summary>
/// 6、根据id修改设置状态
/// </summary>
/// <param name="id">活动信息id</param>
/// <returns>返回受影响的行数</returns>
public static int UpdateSetById(int id, int setState)
{
string sql = "Update Functions set SetState = "+setState+" where FId="+id;
try
{
return DBHelperExecuteCommand(sql);
}
catch(Exception ex)
{
throw ex;
}
}
}
}
下载安装包,安装就行了 网上教程很多 可以用其他的数据库比如Mysql这些,安装方便小巧 SqlServer太大了,下载起都慢,安装也麻烦些,不过如果是教学用的,那么就必装了!! 版本Sql Server 2005 以上的现在都比较流行吧
SQL_SERVER_2008R2中文安装图文教程(windows_64位 *** 作系统 )[win7、8]_百度文库
>
问:工厂中的IQC是什么职位?
答:进货检验员(IQC)
CLInetLabIQC(以下简称IQC)是CLInet在多年开发维护EQA(实验室间质量评价)系统后,成功开发的一套完善的实验室内部的质量评价、质量控制的软件。它不仅包含了每家临床实验室每日必要的质量控制管理模式,而且还集成了完善的网络汇总传递的功能,实现了室内质控的室间质量比对。
IQC不是一个简单的数据管理分析系统,而是建立在大型关系型数据库体系上的很多应用。
在平时开发中hibernate提供的hql基本能够满足我们的日常需求。但是在有些特殊的情况下,还是需要使用原生的sql,并且希望sql查询出来的结果能够绑定到pojo上。
Hibernate中由SQLQuery对象提供对原生sql语句的支持,例如如下语句在查询分析器中编写好后可直接使用
Sql代码
-- 查询采集设备及正在执行的任务 --
select dguidID as deviceId, dstrName as deviceName,
pguidID as portId, pstrName as portName,
tguidTaskID as taskId, tstrName as taskName, tenumRunStatus as runStatus,
todtTaskStartDate as taskStartDate, todtTaskStopDate as taskStopDate
from ULCDevice as d
inner join ULCDevicePort as p on pguidBelongDeviceID = dguidID
left outer join ULCTaskInfo as t on tguidRecordPortID = pguidID and tenumRunStatus = 2
where denumType = 3
order by dguidID;
HibernateCallback中,使用Session创建SQLQuery对象:
Java代码
StringBuffer b = new StringBuffer();
// 省略SQL拼接代码
String sql = btoString();
SQLQuery query = sessioncreateSQLQuery(sql);
最后的重点是如何将查询结果映射到pojo:
SQLQuery接口addScalar方法,可用于设置查询结果到Pojo的映射
SQLQuery addScalar(String columnAlias, Type type)
-- 参数中的Type为Hibernate中提供的数据库类型
如何使用见如下代码:
Java代码
public List<WorkStations> getWorkStations() {
List<WorkStations> retList = thisgetHibernateTemplate()executeFind(new HibernateCallback() {
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
StringBuffer b = new StringBuffer()
append("select dguidID as deviceId, dstrName as deviceName, ")
append("pguidID as portId, pstrName as portName, ")
append("tguidTaskID as taskId, tstrName as taskName, tenumRunStatus as runStatus, ")
append("todtTaskStartDate as taskStartDate, todtTaskStopDate as taskStopDate ")
append("from ULCDevice as d ")
append("inner join ULCDevicePort as p on pguidBelongDeviceID = dguidID ")
append("left outer join ULCTaskInfo as t on tguidRecordPortID = pguidID and tenumRunStatus = 2 ")
append("where denumType = 3 ")
append("order by dguidID");
String sql = btoString();
SQLQuery query = sessioncreateSQLQuery(sql);
queryaddScalar("deviceId", HibernateSTRING);
queryaddScalar("deviceName", HibernateSTRING);
queryaddScalar("portId", HibernateSTRING);
queryaddScalar("portName", HibernateSTRING);
queryaddScalar("taskId", HibernateSTRING);
queryaddScalar("taskName", HibernateSTRING);
queryaddScalar("runStatus", HibernateINTEGER);
queryaddScalar("taskStartDate", HibernateTIMESTAMP);
queryaddScalar("taskStopDate", HibernateTIMESTAMP);
querysetResultTransformer(TransformersaliasToBean(WorkStationsclass));
List<WorkStations> list = querylist();
Systemoutprintln(listsize());
return list;
}
});
return retList;
}
WorkStationsJava
Java代码
public class WorkStations implements Serializable {
private String deviceId = null;
private String deviceName = null;
private String portId = null;
private String portName = null;
private String taskId = null;
private String taskName = null;
private Integer runStatus = null;
private Date taskStartDate = null;
private Date taskStopDate = null;
public WorkStations() {
}
// 省略 getter/sette r方法
}
以上就是关于asp.net中数据库连接的公共类的调用方法全部的内容,包括:asp.net中数据库连接的公共类的调用方法、windows8系统怎么安装sqlserver数据库、请问IQC是什么意思等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)