本文整理汇总了C#中DAL.ExeSqlDataTable方法的典型用法代码示例。如果您正苦于以下问题:C# DAL.ExeSqlDataTable方法的具体用法?C# DAL.ExeSqlDataTable怎么用?C# DAL.ExeSqlDataTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DAL
的用法示例。
在下文中一共展示了DAL.ExeSqlDataTable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _sjTextAdd
//随机生成试题
private string _sjTextAdd(string ID)
{
string SQL = "SELECT [分类ID],[难度配置] FROM [CNGTZ].[dbo].[TK_试卷] where ID=" + ID;
DAL dal = new DAL();
string[] x = dal.RunSqlStrings(SQL);
x[0] = x[0].Substring(1, x[0].Length - 2);
x[1] = x[1].Substring(1, x[1].Length - 2);
DataTable dt1 = dal.RunSqlDataTable("SELECT [ID] FROM [CNGTZ].[dbo].[TK_题目] where 难度=1 and 所属分类 IN(" + x[0] + ") ");//简单题组
DataTable dt2 = dal.RunSqlDataTable("SELECT [ID] FROM [CNGTZ].[dbo].[TK_题目] where 难度=2 and 所属分类 IN(" + x[0] + ") ");//适中题组
DataTable dt3 = dal.RunSqlDataTable("SELECT [ID] FROM [CNGTZ].[dbo].[TK_题目] where 难度=3 and 所属分类 IN(" + x[0] + ") ");//困难题组
DataTable[] dt = new DataTable[] { dt1, dt2, dt3 };
string[] nds = x[1].Split(Convert.ToChar(","));
int[] nd = new int[3];
nd[0] = int.Parse(nds[0]);
nd[1] = int.Parse(nds[1]);
nd[2] = int.Parse(nds[2]);
Random ra = new Random(unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < nd.Length; i++)
{
if (dt[i].Rows.Count > nd[i])//当试题组 题目数量>难度配置 题目数量
{
int xhcs = dt[i].Rows.Count - nd[i];
for (int j = 0; j < xhcs; j++)//随机删除 多余行数
{
int h = ra.Next(0, dt[i].Rows.Count);
if (h >= 0 && h < dt[i].Rows.Count)
{
dt[i].Rows.RemoveAt(h);
}
}
}
}
DataTable dtx = null;
try
{
dal.TranBegin();
dal.ExeSql("create table #testst (id int)");//创建临时表
for (int i = 0; i < dt.Length; i++)
{
foreach (DataRow row in dt[i].Rows)//将 3组 (普通,适中,困难) 题目ID写入临时表
{
SQL = "INSERT INTO #testst (id) VALUES(" + row["ID"].ToString() + ")";
dal.ExeSql(SQL);
}
}
dtx = dal.ExeSqlDataTable("SELECT [ID] FROM [CNGTZ].[dbo].[TK_题目] where ID IN (SELECT id FROM #testst) ORDER BY 题类型,NEWID()");//随机排序后 生成DataTable
dal.ExeSql("DROP TABLE #testst");
dal.TranCommit();
}
catch (Exception)
{
dal.TranRollBack();
}
string retext = "";
if (dtx != null)
{
foreach (DataRow row in dtx.Rows)
{
retext += row["id"].ToString() + ",";
}
retext = "[" + retext.Substring(0, retext.Length - 1) + "]";
}
Sys.DebugMes(retext);
return retext;
}