本文整理汇总了C#中DB.Close方法的典型用法代码示例。如果您正苦于以下问题:C# DB.Close方法的具体用法?C# DB.Close怎么用?C# DB.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
ErrorLabel.Text = "";
int i = 0;
using (SqlConnection conn = new DB().GetConnection())
{
string sql = "Update [ResourceFolders] set [email protected] where ID = @FolderID";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@FolderName", FolderName.Text.Trim());
cmd.Parameters.AddWithValue("@FolderID", LabelFolderID.Text);
conn.Open();
i = cmd.ExecuteNonQuery();
conn.Close();
//将在Resources表中放在文件夹下的资源都更新文件夹名
{
sql = "Update Resources set [email protected] where FolderID = @FolderID";
cmd.CommandText = sql;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();
}
}
if (i == 1)
{
ErrorLabel.Text = "媒体信息更新成功!";
Response.Redirect(Server.HtmlEncode("Folder_Man.aspx"));
}
else
{
ErrorLabel.Text = "媒体信息更新失败,请重试!";
}
}
示例2: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
int i = 0;
string sqlCon = "";
using (SqlConnection conn = new DB().GetConnection())
{
SqlCommand cmd = conn.CreateCommand();
// 删除物理路径下的文件
{
sqlCon = "Select * from Resources where ID in (" + IDSLabel.Text + ")";
cmd.CommandText = sqlCon;
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "FileName");
foreach (DataRow drow in ds.Tables["FileName"].Rows)
{
string FilePath = drow["FilePath"].ToString();
// 删除物理路径下的文件
System.IO.File.Delete(Server.MapPath(FilePath));
}
conn.Close();
}
{
sqlCon = "Delete from Article_Resource where ResourceID in (" + IDSLabel.Text + ")";
cmd.CommandText = sqlCon;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
sqlCon = "Delete from Resources where ID in (" + IDSLabel.Text + ")";
cmd.CommandText = sqlCon;
conn.Open();
i = cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
}
}
if (i > 0)
{
ResultLabel.Text = "成功删除" + i + "个资源!";
ResultLabel.ForeColor = System.Drawing.Color.Green;
Response.Redirect("File_Recycle.aspx");
}
else
{
ResultLabel.Text = "操作失败,请重试!";
ResultLabel.ForeColor = System.Drawing.Color.Red;
}
}
示例3: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
int i = 0;
string sqlCon = "";
using (SqlConnection conn = new DB().GetConnection())
{
SqlCommand cmd = conn.CreateCommand();
sqlCon = "select * from ResourceFolders where FolderName = @FolderName";
cmd.CommandText = sqlCon;
cmd.Parameters.AddWithValue("@FolderName", FolderName.Text);
conn.Open();
SqlDataReader rd = cmd.ExecuteReader();
cmd.Dispose();
if (!rd.Read())
{
conn.Close();
//向resources插入一条记录操作
StringBuilder sb = new StringBuilder("Insert into ResourceFolders (FolderName,FolderType,UserID,CDT,Orders,Resources,ParentFolderID,IsSharedFolder,FoldGUID,Counts)");
sb.Append(" values(@FolderName,@FolderType,@UserID,@CDT,@Orders,@Resources,@ParentFolderID,@IsSharedFolder,@FoldGUID,@Counts)");
cmd = new SqlCommand(sb.ToString(), conn);
cmd.Parameters.AddWithValue("@FolderName", FolderName.Text);
cmd.Parameters.AddWithValue("@FolderType", "");
cmd.Parameters.AddWithValue("@UserID", Session["UserID"].ToString());
cmd.Parameters.AddWithValue("@CDT", DateTime.Now);
cmd.Parameters.AddWithValue("@Orders", 1);
cmd.Parameters.AddWithValue("@Resources", 0);
cmd.Parameters.AddWithValue("@ParentFolderID", 0);
cmd.Parameters.AddWithValue("@IsSharedFolder", 1);
FoldGUID.Text = Guid.NewGuid().ToString();
cmd.Parameters.AddWithValue("@FoldGUID", FoldGUID.Text);
cmd.Parameters.AddWithValue("@Counts", 0);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
//插入成功
i = 1;
}
else
{
ErrorLabel.Text = "文件夹命名重复,请重新输入!";
}
rd.Close();
}
if (i == 1)
{
Response.Redirect(Server.HtmlEncode("Folder_Man.aspx"));
}
}
示例4: CheckExtension
// 判断fileextension是否合法
protected bool CheckExtension(string extension)
{
bool result = false;
// 如果Dictionary的键值数<1,即没有元素,则先读取数据表
if (ResourceTypes.Keys.Count < 1)
{
using (SqlConnection conn = new DB().GetConnection())
{
SqlDataReader rd;
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from ResourceTypes";
conn.Open();
rd = cmd.ExecuteReader();
while (rd.Read())
{
ResourceTypes.Add(rd["Extension"].ToString(), rd["TypeName"].ToString());
}
rd.Close();
conn.Close();
}
}
// 判断是否含有指定的后缀名
if (ResourceTypes.ContainsKey(extension))
{
result = true;
ResourceTypeLabel.Text = ResourceTypes[extension];
}
return result;
}
示例5: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
int i = 0;
using (SqlConnection conn = new DB().GetConnection())
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "Delete from Users where ID in (" + IDSLabel.Text + ") ";
SqlCommand cmd1 = conn.CreateCommand();
cmd1.CommandText = "Delete from Users_UserTags where UserID in (" + IDSLabel.Text + ") ";
conn.Open();
i = cmd.ExecuteNonQuery();
cmd1.ExecuteNonQuery();
cmd.Dispose();
cmd1.Dispose();
cmd.CommandText = "select * from Users where ID in (" + IDSLabel.Text + ") order by ID desc";
SqlDataReader rd = cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
rd.Close();
conn.Close();
}
if (i > 0)
{
string deleteUserName = "个用户,分别为“" + DeleteUserName.Text + " ”" ;
Util.UserUtil_Notes("成功删除了", i, deleteUserName, UserName.Text, "User_Del.aspx", UserIP.Text);
ResultLabel.Text = "成功删除" + i + "个用户!";
ResultLabel.ForeColor = System.Drawing.Color.Green;
}
else
{
ResultLabel.Text = "操作失败,请重试!";
ResultLabel.ForeColor = System.Drawing.Color.Red;
}
}
示例6: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int RoleID = Convert.ToInt16(Session["RoleID"].ToString());
if (Session["RoleID"] == null || Session["UserID"] == null)
{
Util.ShowMessage("用户登录超时,请重新登录!", "Login2.aspx");
}
else if (RoleID > 1)
{
Util.ShowMessage("您没有访问该页面的权限!", "Login2.aspx");
}
else
{
using (SqlConnection conn = new DB().GetConnection())
{
string sql = "select * from UserUtil_Notes order by ID desc";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader rd = cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
rd.Close();
conn.Close();
}
ChangePages();
}
}
}
示例7: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
string Count = "0";
using (SqlConnection conn = new DB().GetConnection())
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select count(*) as Count from Articles where [email protected]";
cmd.Parameters.AddWithValue("@SubID", IDSLabel.Text);
conn.Open();
SqlDataReader rd = cmd.ExecuteReader();
if (rd.Read())
{
Count = rd["Count"].ToString();
}
rd.Close();
if (Count == "0")
{
Del();
}
else
{
Response.Write("<script>alert(' 操作失败!! \\n \\n 该栏目下仍存在文章,请删除该栏目下的文章后,才能对栏目进行删除!')</script>");
}
conn.Close();
}
}
示例8: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
int i = 0;
using (SqlConnection conn = new DB().GetConnection())
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "Delete from SubMenu where ID in (" + IDSLabel.Text + ") ";
conn.Open();
i = cmd.ExecuteNonQuery();
cmd.Dispose();
cmd.CommandText = "select * from SubMenu where ID in (" + IDSLabel.Text + ") order by ID desc";
SqlDataReader rd = cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
rd.Close();
conn.Close();
}
if (i > 0)
{
ResultLabel.Text = "成功删除!";
ResultLabel.ForeColor = System.Drawing.Color.Green;
}
else
{
ResultLabel.Text = "操作失败,请重试!";
ResultLabel.ForeColor = System.Drawing.Color.Red;
}
}
示例9: LoadGuildMembers
public void LoadGuildMembers()
{
try
{
LoadGuildMemberIds(Character.Network.Guild.Guildid, ref Character.Network.Guild.Members);
foreach (int m in Character.Network.Guild.Members)
{
Global.guild_player PlayerGuild = new Global.guild_player();
PlayerGuild.MemberID = m;
DB ms = new DB("SELECT * FROM character WHERE id='" + m + "'");
using (System.ObjData.Manager.SqlClient.SqlDataReader reader = ms.Read())
{
while (reader.Read())
{
PlayerGuild.Model = reader.GetInt32(3);
PlayerGuild.Xsector = reader.GetByte(16);
PlayerGuild.Ysector = reader.GetByte(17);
PlayerGuild.Level = reader.GetByte(5);
PlayerGuild.Name = reader.GetString(2);
PlayerGuild.Online = (reader.GetInt32(47) == 1);
if (PlayerGuild.Online)
{
Systems sys = GetPlayerMainid(m);
if (sys != null)
Character.Network.Guild.MembersClient.Add(sys.client);
}
}
}
ms.Close();
DB ms2 = new DB("SELECT * FROM guild_members WHERE guild_member_id='" + m + "'");
using (System.ObjData.Manager.SqlClient.SqlDataReader reader2 = ms2.Read())
{
while (reader2.Read())
{
PlayerGuild.joinRight = (reader2.GetByte(7) == 1);
PlayerGuild.withdrawRight = (reader2.GetByte(8) == 1);
PlayerGuild.unionRight = (reader2.GetByte(9) == 1);
PlayerGuild.guildstorageRight = (reader2.GetByte(10) == 1);
PlayerGuild.noticeeditRight = (reader2.GetByte(11) == 1);
PlayerGuild.FWrank = reader2.GetByte(6);
PlayerGuild.DonateGP = reader2.GetInt32(4);
PlayerGuild.Rank = reader2.GetByte(3);
}
}
ms2.Close();
Character.Network.Guild.MembersInfo.Add(PlayerGuild);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
示例10: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (SqlConnection conn = new DB().GetConnection())
{
// 焦点图
string sql = "select * from Focuses where valid = 1 order by orders desc";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader rd = cmd.ExecuteReader();
Repeater1.DataSource = rd;
Repeater1.DataBind();
rd.Close();
// GridView1 教师通知
cmd.CommandText = "select top 10 ID,Title,CDT from Articles where SubID = 6 and Status =1 and Finished = 1 and Valid = 1 Order by Orders Desc,CDT Desc,ID Desc";
rd = cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
rd.Close();
// GridView2 学生通知
cmd.CommandText = "select top 10 ID,Title,CDT from Articles where SubID = 7 and Status =1 and Finished = 1 and Valid = 1 Order by Orders Desc,CDT Desc,ID Desc";
rd = cmd.ExecuteReader();
GridView2.DataSource = rd;
GridView2.DataBind();
rd.Close();
// GridView3 学院动态
cmd.CommandText = "select top 10 ID,Title,CDT from Articles where SubID = 5 and Status =1 and Finished = 1 and Valid = 1 Order by Orders Desc,CDT Desc,ID Desc";
rd = cmd.ExecuteReader();
GridView3.DataSource = rd;
GridView3.DataBind();
rd.Close();
// GridView4 作品展示
cmd.CommandText = "select top 4 ID,Title,Abs,Author,CoverPhotoURL,CDT,Catalog from Shows where Status =1 Order by Orders Desc,CDT Desc,ID Desc";
rd = cmd.ExecuteReader();
GridView4.DataSource = rd;
GridView4.DataBind();
rd.Close();
// GridView5 活动剪影
cmd.CommandText = "select top 10 ID,Title,CDT from Articles where SubID = 39 and Status =1 and Finished = 1 and Valid = 1 Order by Orders Desc,CDT Desc,ID Desc";
rd = cmd.ExecuteReader();
GridView5.DataSource = rd;
GridView5.DataBind();
rd.Close();
conn.Close();
}
}
}
示例11: DelBtn_Click
protected void DelBtn_Click(object sender, EventArgs e)
{
string ids = "";
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox checkBox = (CheckBox)GridView1.Rows[i].FindControl("ChechBox1");
if (checkBox.Checked == true)
{
ids += "," + GridView1.DataKeys[i].Value;
}
}
if (!String.IsNullOrEmpty(ids))
{
ids = ids.Substring(1);
IDS.Text = ids;
string[] array = ids.Split(',');
int k = array.Length;
using (SqlConnection conn = new DB().GetConnection())
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "Delete from Articles where ID in (" + IDS.Text + ")";
//cmd.Parameters.AddWithValue("@ID", IDS.Text);
conn.Open();
cmd.ExecuteNonQuery();
cmd.Dispose();
MyDataBind();
conn.Close();
}
}
else
{
Response.Write("<script language='javascript'> alert('至少选择一项');</script>");
}
//string ids = "";
//for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
//{
// CheckBox checkBox = (CheckBox)GridView1.Rows[i].FindControl("ChechBox1");
// if (checkBox.Checked == true)
// {
// ids += "," + GridView1.DataKeys[i].Value;
// }
//}
//if (!String.IsNullOrEmpty(ids))
//{
// ids = ids.Substring(1);
// Response.Redirect(Server.HtmlEncode("Article_DelTrue1.aspx?IDS=" + ids));
//}
}
示例12: btnGet_Click
protected void btnGet_Click(object sender, EventArgs e)
{
i++;
string userNameStr = txtName.Text;
string answer1 = "";
string answer2 = "";
string answer3 = "";
using (SqlConnection conn = new DB().GetConnection())
{
string sql = "select top 1 ID,Answer1,Answer2,Answer3 from [UserQuestion_ForFindPassword] where UserName = @UserName ORDER by ID DESC";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@UserName", txtName.Text);
conn.Open();
SqlDataReader rd = cmd.ExecuteReader();
if (rd.Read())
{
answer1 = rd["Answer1"].ToString();
answer2 = rd["Answer2"].ToString();
answer3 = rd["Answer3"].ToString();
}
rd.Close();
if (txtAnswer1.Text == answer1 && txtAnswer2.Text == answer2 && txtAnswer3.Text == answer3)
{
PanelGetPass.Visible = false;
ResetPassword.Visible = true;
}
else
{
Label1.Text = "答案不正确";
if (i < 5)
{
Response.Write("<script language='javascript'> alert('答案不正确,你还有" + (5 - i) + "次机会');</script>");
}
else
{
i = 0;
cmd.CommandText = "update Users set CongealDate = @CongealDate where UserName = @UserName2 ";
cmd.Parameters.AddWithValue("@UserName2", txtName.Text);
cmd.Parameters.AddWithValue("@CongealDate", DateTime.Now.ToString());
cmd.ExecuteNonQuery();
cmd.Dispose();
Response.Write("<script language='javascript'> alert('答案不正确,您的5次机会已经用完,在24小时以后才能使用此功能找回密码');</script>");
PanelInputName.Visible = true;
PanelGetPass.Visible = false;
}
}
conn.Close();
}
}
示例13: ButtonSave_Click
protected void ButtonSave_Click(object sender, EventArgs e)
{
int i;
/*SqlConnection conn = new SqlConnection(@"server=QH-20160713TJQE\SQLEXPRESS;database=SETC;Trusted_Connection=True");
string Sql = "INSERT INTO Cats (CatName,Description) values ('" + CatName.Text + "','" + Description.Text + "')";
SqlCommand cmd = new SqlCommand(Sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();*/
using (SqlConnection conn = new DB().GetConnection())
{
StringBuilder sb = new StringBuilder("Insert into Cats (CatName,Description,Valid,IsShow) ");
sb.Append(" values ( @CatName,@Description,@Valid,@IsShow) ");
SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
cmd.Parameters.AddWithValue("@Description", Description.Text);
cmd.Parameters.AddWithValue("@CatName", CatName.Text);
string radiobuttonvalue = "";
if (true1.Checked)
{
radiobuttonvalue = true1.Text;
}
else if (false1.Checked)
{
radiobuttonvalue = false1.Text;
}
cmd.Parameters.AddWithValue("@Valid", radiobuttonvalue);
conn.Open();
string radiobuttonIsShow = "";
if (true2.Checked)
{
radiobuttonvalue = "1";
}
else if (false2.Checked)
{
radiobuttonvalue = "0";
}
cmd.Parameters.AddWithValue("@IsShow", radiobuttonIsShow);
i=cmd.ExecuteNonQuery();
conn.Close();
if (i == 1)
{
Response.Write("<script language='javascript'> alert('操作成功');window.location='Cat_Man.aspx';</script>");
}
else
{
Response.Write("<script language='javascript'> alert('操作失败,请重试!');window.location='Cat_Man.aspx';</script>");
}
}
}
示例14: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
ErrorLabel.Text = "";
string folderIDOld="";
int i = 0;
using (SqlConnection conn = new DB().GetConnection())
{
string sql1 = "Select * from [Resources] where ID = @ResourceID";
SqlCommand cmd = new SqlCommand(sql1, conn);
cmd.Parameters.AddWithValue("@ResourceID", LabelResourceID.Text);
conn.Open();
SqlDataReader rd = cmd.ExecuteReader();
if (rd.Read())
{
folderIDOld = rd["FolderID"].ToString();
}
conn.Close();
string sql = "Update [Resources] set [email protected],[email protected],[email protected] where ID = @ResourceID;Update ResourceFolders set Counts = Counts-1 where ID = @ID1;Update ResourceFolders set Counts = Counts+1 where ID = @FolderID";
cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@ResourceName", ResourceName.Text.Trim());
cmd.Parameters.AddWithValue("@FolderID", FolderDDL.SelectedItem.Value);
cmd.Parameters.AddWithValue("@FolderName", FolderDDL.SelectedItem.Text);
cmd.Parameters.AddWithValue("@ResourceID", LabelResourceID.Text);
cmd.Parameters.AddWithValue("@ID1", folderIDOld);
conn.Open();
i = cmd.ExecuteNonQuery();
conn.Close();
}
if (i == 3)
{
ErrorLabel.Text = "媒体信息更新成功!";
Response.Redirect(Server.HtmlEncode("File_Man.aspx"));
}
else
{
ErrorLabel.Text = "媒体信息更新失败,请重试!";
}
}
示例15: MyDataBind
protected void MyDataBind()
{
using (SqlConnection conn = new DB().GetConnection())
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "Select * from Items where ShowID = '" + IDLabel.Text + "' order by Orders desc, ID desc";
conn.Open();
SqlDataReader rd = cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
rd.Close();
conn.Close();
}
}