本文整理汇总了C#中DBConnector.ExecuteObject方法的典型用法代码示例。如果您正苦于以下问题:C# DBConnector.ExecuteObject方法的具体用法?C# DBConnector.ExecuteObject怎么用?C# DBConnector.ExecuteObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnector
的用法示例。
在下文中一共展示了DBConnector.ExecuteObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ButtonLogin_Click
protected void ButtonLogin_Click(object sender, EventArgs e)
{
String strSql = "Select count(*) from Users where ID =" + TextBoxUserName.Text + " And Pwd = '" +
Helper.CalMD5(TextBoxPassword.Text) + "'";
DBConnector db = new DBConnector();
if ((Int32)db.ExecuteObject(strSql) > 0)
{
Helper.UserId = int.Parse(TextBoxUserName.Text);
strSql = "SELECT Name FROM Users WHERE ID = " + Helper.UserId;
Helper.UserName = (String)db.ExecuteObject(strSql);
strSql = "SELECT IsAdmin FROM Users WHERE ID = " + Helper.UserId;
Helper.IsAdmin = (bool)db.ExecuteObject(strSql);
if (Helper.IsAdmin)
{
MultiView1.SetActiveView(ViewAdministrator);
LabelAdminName.Text = Helper.UserName;
LinkButton2.Visible = true;
}
else
{
MultiView1.SetActiveView(ViewUsers);
LabelUserName.Text = Helper.UserName;
LinkButton2.Visible = true;
}
Response.Redirect(".");
}
else
{
Helper.MsgBox("登陆失败");
}
}
示例2: ButtonUpload2_Click
protected void ButtonUpload2_Click(object sender, EventArgs e)
{
String strMd5 = "";
int iLength = 0;
String strFileName = "";
//如果上传控件已选择文件
if (FileUpload1.HasFile)
{
strFileName = FileUpload1.FileName;
//将文件上传到零时目录下
FileUpload1.SaveAs(Server.MapPath(".\\Temp\\" + strFileName));
//将文件读取到字符串
String contents = File.ReadAllText(Server.MapPath(".\\Temp\\" + strFileName));
//计算文件 MD5 值
strMd5 = Helper.CalMD5(contents);
//检查 MD5 是否在系统中存在,即文件是否重复。
DBConnector db = new DBConnector();
int n = (int)db.ExecuteObject("Select count(*) From Files Where MD5='" + strMd5 + "'");
if (n > 0)
{
//如果重复,删除该文件
File.Delete(Server.MapPath(".\\Temp\\" + strFileName));
Helper.MsgBox("系统中已存在该文件", "./ViewFile.aspx?MD5=" + strMd5);
}
else//否则
{
//将文件移动到上传目录下
File.Move(Server.MapPath(".\\Temp\\" + strFileName), Server.MapPath(".\\Uploads\\" + strFileName));
//计算文件长度
iLength = FileUpload1.PostedFile.ContentLength;
//插入文件记录
String strSql = String.Format("Insert into Files (MD5, Title, Brief, Size, Point, UploadTime, UploaderId, FilePath, FileName)" +
" Values('{0}', '{1}', '{2}', {3}, {4}, '{5}', {6}, '.\\Uploads\\', '{7}')", strMd5,
TextBoxTitle.Text, TextBoxBrief.Text, iLength, TextBoxPoint.Text, DateTime.Now.ToString(),
Helper.UserId, strFileName);
db.ExecuteNonQuery(strSql);
Helper.MsgBox("上传成功", "./ViewFile.aspx?MD5=" + strMd5);
}
}
}
示例3: ButtonAddUser_Click
protected void ButtonAddUser_Click(object sender, EventArgs e)
{
//1、检查学号是否已存在
String strSql = String.Format("Select Count(*) From Users Where ID = '{0}'", TextBoxUserId.Text);
DBConnector db = new DBConnector();
if ((Int32)db.ExecuteObject(strSql) != 0 )
{
Helper.MsgBox("该用户已存在");
return;
}
else
{
//是否管理员
Int32 iIsAdmin;
if (CheckBoxIsAdmin.Checked == true)
{
iIsAdmin = 1;
}
else
{
iIsAdmin = 0;
}
strSql = String.Format(@"Insert Into Users(ID, Pwd, Name, ClassId, Point, AddTime, IsAdmin, IsDeleted)
Values({0}, '{1}', '{2}', {3}, 0, '{4}', {5}, 0)", TextBoxUserId.Text, Helper.CalMD5(TextBoxPwd.Text),
TextBoxName.Text, DropDownListClass.SelectedIndex, DateTime.Now, iIsAdmin);
if (db.ExecuteNonQuery(strSql) == true)
{
Helper.MsgBox("添加失败");
}
else
{
Helper.MsgBox("添加成功", "Default.aspx");
}
}
}