zoukankan
html css js c++ java
更新数据的经典代码
private
void
UpdateUser()
{
if
(Page.IsValid)
{
//
Update the existing user
SqlConnection con;
string
sql;
SqlCommand cmd;
StringBuilder sb
=
new
StringBuilder();
ArrayList values
=
new
ArrayList();
//
Build the SQL string
sb.Append(
"
UPDATE [User] SET
"
);
sb.Append(
"
Login='{0}', Password='{1}', FirstName='{2}',
"
);
sb.Append(
"
LastName='{3}', PhoneNumber='{4}', Email='{5}'
"
);
//
Add required values to replace
values.Add(txtLogin.Text);
values.Add(txtPwd.Text);
values.Add(txtFName.Text);
values.Add(txtLName.Text);
values.Add(txtPhone.Text);
values.Add(txtEmail.Text);
//
Add optional values directly
if
(txtAddress.Text
!=
string
.Empty)
sb.Append(
"
, Address='
"
+
txtAddress.Text
+
"
'
"
);
if
(txtMobile.Text
!=
string
.Empty)
sb.Append(
"
, CellNumber='
"
+
txtMobile.Text
+
"
'
"
);
if
(txtBirth.Text
!=
string
.Empty)
{
//
Pass date in ISO format YYYMMDD
DateTime dt
=
DateTime.Parse(txtBirth.Text);
sb.Append(
"
, DateOfBirth='
"
);
sb.Append(dt.Year.ToString(
"
d4
"
));
sb.Append(dt.Month.ToString(
"
d2
"
));
sb.Append(dt.Day.ToString(
"
d2
"
));
sb.Append(
"
'
"
);
}
sb.Append(
"
WHERE UserID='{6}'
"
);
//
Get the UserID from the context.
values.Add(Context.User.Identity.Name);
sql
=
String.Format(sb.ToString(), values.ToArray());
//
Connect and execute the query
con
=
new
SqlConnection(
"
data source=(local)\\NetSdk;initial catalog=FriendsData;user id=sa
"
);
cmd
=
new
SqlCommand(sql, con);
con.Open();
bool
doredirect
=
true
;
try
{
cmd.ExecuteNonQuery();
}
catch
{
doredirect
=
false
;
this
.lblMessage.Visible
=
true
;
this
.lblMessage.Text
=
"
Couldn't update your profile!
"
;
}
finally
{
con.Close();
}
if
(doredirect)
Server.Transfer(
"
../Default.aspx
"
);
}
}
查看全文
相关阅读:
centos8.2安装nginx
Centos8安装PostgreSQL
PostgreSQL 安装时提示下载元数据失败
MySQL8定时备份
Centos8安装Docker
Centos8安装中文字体
Centos8源码安装libgdiplus
MySQL拖拽排序
MySQL8修改事务隔离级别
MySQL启动问题
原文地址:https://www.cnblogs.com/ahuang1118/p/172517.html
最新文章
Android中Activity的启动模式(LaunchMode)和使用场景
adb shell dumpsys activity activities调用信息分析
使用python读取csv文件快速插入数据库的实例
vue脚手架 build-config文件夹(跨域/打包)相关配置
Python标准库映射类型与可散列数据类型的关系
python字符串常用方法
javaScript实现滚动条事件详解
Java 网页抓取
JS如何给ul下的所有li绑定点击事件,点击使其弹出下标和内容
JS实现的四级密码强度检测功能示例
热门文章
PHP中的 抽象类(abstract class)和 接口(interface)
mysql 启动1067错误及修改字符集重启之后复原无效问题
后台开发:核心技术与应用实践 -- C++
Effective C++笔记
完全虚拟化和半虚拟化区别
按键初始化
React---面向组件编程
React---JSX的使用
React---学习开篇
SqlServer创建链接服务器
Copyright © 2011-2022 走看看