本文整理汇总了C#中DAO.GetDataTable方法的典型用法代码示例。如果您正苦于以下问题:C# DAO.GetDataTable方法的具体用法?C# DAO.GetDataTable怎么用?C# DAO.GetDataTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DAO
的用法示例。
在下文中一共展示了DAO.GetDataTable方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (this.Request.QueryString["docid"] != null)
{
string ls_docid = this.Request.QueryString["docid"].ToString();
//根据文档ID得到记录
DAO db = new DAO();
string sql = "select * from hyp_flowmain where DOCID='" + ls_docid + "'";
DataTable dt = db.GetDataTable(sql);
string ls_flowid, ls_flowname, ls_mudelid, ls_curtacheid, ls_curtachename;
if (dt.Rows.Count > 0)
{
ls_flowid = dt.Rows[0]["hy_flowid"].ToString(); //流程ID
ls_flowname = dt.Rows[0]["hy_flowname"].ToString(); //流程名称
ls_mudelid = dt.Rows[0]["hy_mudelid"].ToString(); //模块ID
ls_curtacheid = dt.Rows[0]["hy_curtacheid"].ToString(); //当前环节ID
ls_curtachename = dt.Rows[0]["hy_curtachename"].ToString(); //当前环节名称
HyOperationlog HyOperationlog = new HyOperationlog();
//制作表格式信息
this.txtCurrnetDocFlow.Text = HyOperationlog.GetCurrnetDocFlow(ls_docid, ls_flowid, ls_flowname, ls_mudelid, ls_curtacheid, ls_curtachename);
}
}
}
示例2: getClass
private string getClass(string strType)
{
if (this.ddl_tableid.SelectedValue == "")
{
Response.Write("<script>alert('对不起,请输入表名!!!');</script>");
this.lb_showsql.Text = " ";
return "";
}
if (this.txt_con.Value != "")
{
strCon = this.txt_con.Value;
}
else
{
strCon = "server=(local);database=" + this.ddl_database.SelectedValue + ";uid=sa;[email protected]#$%^*(sa;";
}
DAO db = new DAO();
//得到字段
string sqlSelect = " select a.name as [name],b.name as type from syscolumns a,systypes b where a.id=object_id('" + this.ddl_tableid.SelectedValue + "') and a.xtype=b.xtype";
if (this.txt_sql.Value != "")
{
string[] arrySql = txt_sql.Value.Split('#');
string sqlWhere = "";
for (int i = 0; i < arrySql.Length; i++)
{
if (i == arrySql.Length - 1)
{
sqlWhere += "'" + arrySql[i] + "'";
}
else
{
sqlWhere += "'" + arrySql[i] + "',";
}
}
sqlSelect += " and a.name not in(" + sqlWhere + ") ";
}
DataTable dt = new DataTable();
try
{
dt = db.GetDataTable(sqlSelect);
}
catch (Exception ex)
{
throw ex;
Response.Write("<script>alert('对不起,连接串输入有错误,系统将重置!');</script>");
this.txt_con.Value = "";
if (this.Session["constr"] != null)
{
this.Session["constr"] = null;
}
Response.Write("<script>window.location='" + this.Request.Url.ToString() + "';</script>");
}
string strInsert = " ";
//构造类属性
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (strType == "1")
{
strInsert += "public " + getClassType(dt.Rows[i]["type"].ToString()) + " " + dt.Rows[i]["name"].ToString() + "; <br/>";
}
else
{
strInsert += "public " + getClassType(dt.Rows[i]["type"].ToString()) + " " + dt.Rows[i]["name"].ToString() + ";\r\n";
}
}
}
return strInsert;
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//对连接串赋值
if (this.Session["constr"] != null)
{
this.txt_con.Value = this.Session["constr"].ToString();
}
if (!this.IsPostBack)
{
//连接数据库
DAO db = new DAO();
//找到库名
string sqlSelect = " SELECT Name from Master..SysDatabases ORDER BY Name ";
DataTable dt = new DataTable();
try
{
dt = db.GetDataTable(sqlSelect);
}
catch (Exception ex)
{
Response.Write("<script>alert('对不起,连接串输入有错误,sql生成器急将重置!');</script>");
this.txt_con.Value = "";
if (this.Session["constr"] != null)
{
this.Session["constr"] = null;
}
Response.Write("<script>window.location='" + this.Request.Url.ToString() + "';</script>");
}
this.ddl_database.DataSource = dt;
this.ddl_database.DataTextField = "name";
this.ddl_database.DataValueField = "name";
this.ddl_database.DataBind();
this.ddl_database.Items.Insert(0, new ListItem("--请选择--", ""));
this.ddl_tableid.Items.Insert(0, new ListItem("--请选择--", ""));
}
}
示例4: ddl_database_SelectedIndexChanged
protected void ddl_database_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddl_database.SelectedValue != "")
{
DAO db = new DAO();
string sqlSelect = " SELECT Name FROM " + ddl_database.SelectedValue + "..SysObjects Where XType='U' ORDER BY Name ";
DataTable dt = new DataTable();
try
{
dt = db.GetDataTable(sqlSelect);
}
catch (Exception ex)
{
Response.Write("<script>alert('对不起,连接串输入有错误,系统将重置!');</script>");
this.txt_con.Value = "";
if (this.Session["constr"] != null)
{
this.Session["constr"] = null;
}
Response.Write("<script>window.location='" + this.Request.Url.ToString() + "';</script>");
}
this.ddl_tableid.DataSource = dt;
this.ddl_tableid.DataTextField = "name";
this.ddl_tableid.DataValueField = "name";
this.ddl_tableid.DataBind();
this.ddl_tableid.Items.Insert(0, new ListItem("--请选择--", ""));
}
this.lb_showsql.Text = " ";
}
示例5: btn_update_Click
//得到update语句
protected void btn_update_Click(object sender, EventArgs e)
{
string sqlWhere = "";
if (this.ddl_tableid.SelectedValue == "")
{
Response.Write("<script>alert('对不起,请输入表名!!!');</script>");
this.lb_showsql.Text = " ";
return;
}
if (this.txt_con.Value != "")
{
strCon = this.txt_con.Value;
}
else
{
strCon = "server=(local);database=" + this.ddl_database.SelectedValue + ";uid=sa;[email protected]#$%^*(sa;";
}
DAO db = new DAO();
//得到字段名
string sqlSelect = " select name from syscolumns where id=object_id('" + this.ddl_tableid.SelectedValue + "') ";
if (this.txt_sql.Value != "")
{
string[] arrySql = txt_sql.Value.Split('#');
for (int i = 0; i < arrySql.Length; i++)
{
if (i == arrySql.Length - 1)
{
sqlWhere += "'" + arrySql[i] + "'";
}
else
{
sqlWhere += "'" + arrySql[i] + "',";
}
}
}
if (this.txt_where.Value != "")
{
string[] arrySql = txt_where.Value.Split('#');
for (int i = 0; i < arrySql.Length; i++)
{
if (i == 0 && sqlWhere != "")
{
sqlWhere += ",'" + arrySql[i] + "',";
}
else if (i == arrySql.Length - 1)
{
sqlWhere += "'" + arrySql[i] + "'";
}
else
{
sqlWhere += "'" + arrySql[i] + "',";
}
}
}
if (this.txt_sql.Value != "" || this.txt_where.Value != "")
{
sqlSelect += " and name not in(" + sqlWhere + ") ";
}
DataTable dt = new DataTable();
try
{
dt = db.GetDataTable(sqlSelect);
}
catch (Exception ex)
{
Response.Write("<script>alert('对不起,连接串输入有错误,系统将重置!');</script>");
this.txt_con.Value = "";
if (this.Session["constr"] != null)
{
this.Session["constr"] = null;
}
Response.Write("<script>window.location='" + this.Request.Url.ToString() + "';</script>");
}
//开始构造update语句
string strUpdate = "sqlUpdate=\" update " + this.ddl_tableid.SelectedValue + " set ";
if (dt.Rows.Count > 0)
{
int j = 1;
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i == 0)
{
strUpdate += dt.Rows[0]["name"].ToString() + "[email protected]" + dt.Rows[0]["name"].ToString();
}
else
{
strUpdate += "," + dt.Rows[i]["name"].ToString() + "[email protected]" + dt.Rows[i]["name"].ToString();
}
if (strUpdate.Length > (100 * j))
{
strUpdate += "\";</br>sqlUpdate+=\"";
j++;
}
}
}
if (this.txt_where.Value != "")
{
strUpdate += " where 1=1";
string[] arryWhere = this.txt_where.Value.Split('#');
//.........这里部分代码省略.........
示例6: btn_sqlparam_Click
//得到sqlparam
protected void btn_sqlparam_Click(object sender, EventArgs e)
{
if (this.ddl_tableid.SelectedValue == "")
{
Response.Write("<script>alert('对不起,请输入表名!!!');</script>");
this.lb_showsql.Text = " ";
return;
}
DAO db = new DAO();
//得到字段和字段类型
string sqlSelect = " select a.name as [name],b.name as type from syscolumns a,systypes b where a.id=object_id('" + this.ddl_tableid.SelectedValue + "') and a.xtype=b.xtype";
if (this.txt_sql.Value != "")
{
//过滤条件
string[] arrySql = txt_sql.Value.Split('#');
string sqlWhere = "";
for (int i = 0; i < arrySql.Length; i++)
{
if (i == arrySql.Length - 1)
{
sqlWhere += "'" + arrySql[i] + "'";
}
else
{
sqlWhere += "'" + arrySql[i] + "',";
}
}
sqlSelect += " and a.name not in(" + sqlWhere + ") ";
}
DataTable dt = new DataTable();
try
{
dt = db.GetDataTable(sqlSelect);
}
catch (Exception ex)
{
Response.Write("<script>alert('对不起,连接串输入有错误,系统将重置!');</script>");
this.txt_con.Value = "";
if (this.Session["constr"] != null)
{
this.Session["constr"] = null;
}
Response.Write("<script>window.location='" + this.Request.Url.ToString() + "';</script>");
}
//开始构造
string strInsert = " SqlParameter[] sqlparam = {";
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i == dt.Rows.Count - 1)
{
strInsert += " <br/> db.MakeInParam(\"@" + dt.Rows[i]["name"].ToString() + "\",SqlDbType." + getDateType(dt.Rows[i]["type"].ToString()) + "," + dt.Rows[i]["name"].ToString() + ")";
}
else
{
strInsert += "db.MakeInParam(\"@" + dt.Rows[i]["name"].ToString() + "\",SqlDbType." + getDateType(dt.Rows[i]["type"].ToString()) + "," + dt.Rows[i]["name"].ToString() + "),<br/>";
}
}
strInsert += "};";
}
//前台显示出来
this.lb_showsql.Text = strInsert;
}
示例7: btn_speed_Click
//得到sql的执行速度
protected void btn_speed_Click(object sender, EventArgs e)
{
if (this.txt_sql.Value == "")
{
Response.Write("<script>alert('对不起,请输入sql语句!!!');</script>");
return;
}
return;
string sqlActive = " Declare @d Datetime Set @d=GetDate() " + this.txt_sql.Value + " Select [datetime]=DateDiff(ms,@d,GetDate()) ";
if (this.txt_con.Value != "")
{
strCon = this.txt_con.Value;
}
else
{
strCon = "server=(local);database=" + this.ddl_database.SelectedValue + ";uid=sa;[email protected]#$%^*(sa;";
}
DAO db = new DAO();
DataTable dt = db.GetDataTable(sqlActive);
if (dt.Rows.Count > 0)
{
this.lb_showsql.Text = "SQL的执行速度为:" + dt.Rows[0]["datetime"].ToString();
}
}
示例8: btn_insert2_Click
protected void btn_insert2_Click(object sender, EventArgs e)
{
if (this.ddl_tableid.SelectedValue == "")
{
Response.Write("<script>alert('对不起,请输入表名!!!');</script>");
this.lb_showsql.Text = " ";
return;
}
if (this.txt_con.Value != "")
{
strCon = this.txt_con.Value;
}
else
{
strCon = "server=(local);database=" + this.ddl_database.SelectedValue + ";uid=sa;[email protected]#$%^*(sa;";
}
DAO db = new DAO();
//得到字段
string sqlSelect = " select name from syscolumns where id=object_id('" + this.ddl_tableid.SelectedValue + "') ";
if (this.txt_sql.Value != "")
{
string[] arrySql = txt_sql.Value.Split('#');
string sqlWhere = "";
//构造where条件句
for (int i = 0; i < arrySql.Length; i++)
{
if (i == arrySql.Length - 1)
{
sqlWhere += "'" + arrySql[i] + "'";
}
else
{
sqlWhere += "'" + arrySql[i] + "',";
}
}
sqlSelect += " and name not in(" + sqlWhere + ") ";
}
DataTable dt = new DataTable();
try
{
dt = db.GetDataTable(sqlSelect);
}
catch (Exception ex)
{
Response.Write("<script>alert('对不起,连接串输入有错误,系统将重置!');</script>");
this.txt_con.Value = "";
if (this.Session["constr"] != null)
{
this.Session["constr"] = null;
}
Response.Write("<script>window.location='" + this.Request.Url.ToString() + "';</script>");
}
//开始构造insert
string strInsert = " insert into " + this.ddl_tableid.SelectedValue + "( ";
int j = 1;
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i == 0)
{
strInsert += dt.Rows[0]["name"].ToString();
}
else
{
strInsert += "," + dt.Rows[i]["name"].ToString();
}
//对sql进行格式化
if (strInsert.Length > (100 * j))
{
strInsert += "</br>";
j++;
}
}
strInsert += ") values ( ";
string flowid = "";
for (int i = 0; i < dt.Rows.Count; i++)
{
flowid = dt.Rows[i]["name"].ToString();
if (flowid.IndexOf("hyc") != -1)
{
flowid = flowid.Substring(4);
}
if (flowid.IndexOf("hy_") != -1)
{
flowid = flowid.Substring(3);
}
if (i == 0)
{
strInsert += "'\"+this." + flowid + ".Value+\"'";
}
else
{
strInsert += ",'\"+this." + flowid + ".Value+\"'";
}
//对sql进行格式化
if (strInsert.Length > (100 * j))
{
strInsert += "</br>";
j++;
//.........这里部分代码省略.........
示例9: getInsert
private string getInsert(string strType)
{
if (this.ddl_tableid.SelectedValue == "")
{
Response.Write("<script>alert('对不起,请输入表名!!!');</script>");
this.lb_showsql.Text = " ";
return "";
}
if (this.txt_con.Value != "")
{
strCon = this.txt_con.Value;
}
else
{
strCon = "server=(local);database=" + this.ddl_database.SelectedValue + ";uid=sa;[email protected]#$%^*(sa;";
}
DAO db = new DAO();
//得到字段
string sqlSelect = " select name from syscolumns where id=object_id('" + this.ddl_tableid.SelectedValue + "') ";
if (this.txt_sql.Value != "")
{
string[] arrySql = txt_sql.Value.Split('#');
string sqlWhere = "";
//构造where条件句
for (int i = 0; i < arrySql.Length; i++)
{
if (i == arrySql.Length - 1)
{
sqlWhere += "'" + arrySql[i] + "'";
}
else
{
sqlWhere += "'" + arrySql[i] + "',";
}
}
sqlSelect += " and name not in(" + sqlWhere + ") ";
}
DataTable dt = new DataTable();
try
{
dt = db.GetDataTable(sqlSelect);
}
catch (Exception ex)
{
Response.Write("<script>alert('对不起,连接串输入有错误,系统将重置!');</script>");
this.txt_con.Value = "";
if (this.Session["constr"] != null)
{
this.Session["constr"] = null;
}
Response.Write("<script>window.location='" + this.Request.Url.ToString() + "';</script>");
}
//开始构造insert
string strInsert = " sqlInsert =\" insert into " + this.ddl_tableid.SelectedValue + "( ";
int j = 1;
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i == 0)
{
strInsert += dt.Rows[0]["name"].ToString();
}
else
{
strInsert += "," + dt.Rows[i]["name"].ToString();
}
//对sql进行格式化
if (strInsert.Length > (100 * j))
{
if (strType == "1")
{
strInsert += "\";</br> sqlInsert +=\" ";
}
else
{
strInsert += "\";\r\nsqlInsert +=\" ";
}
j++;
}
}
strInsert += ") values ( ";
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i == 0)
{
strInsert += "@" + dt.Rows[0]["name"].ToString();
}
else
{
strInsert += ",@" + dt.Rows[i]["name"].ToString();
}
//对sql进行格式化
if (strInsert.Length > (100 * j))
{
if (strType == "1")
{
strInsert += "\";</br> sqlInsert +=\" ";
}
//.........这里部分代码省略.........