Asp.Net从零开始学-22
来源:互联网 发布:新媒体营销 数据分析 编辑:程序博客网 时间:2024/05/18 02:23
简单提一下WebService
[WebMethod]
public string HelloWorld(string name)
{
return "Hello+name";
}
<form name="f1" method="post" action="http://localhost/WebServiceTest/Service1.asmx/HelloWorld">
<input type="text" name="name"><input type="submit"> <!--name="name"通过此传-->
</form>
[WebMethod(Description="获取库存")]
public DataSet getStore(){
SqlConnection con=new SqlConnection("server=.;database=store;uid=sa;pwd=12345678");
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("select * from store",con);
DataSet ds=new DataSet();
sda.Fill(ds,"store");
return ds;
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
WebServiceTest.Service1 ss=new WebServiceTest.Service1();
this.DataGrid1.DataSource=ss.getStore();
this.DataGrid1.DataBind();
}
[WebMethod]
public string AtoB(int sum){
try{
this.decrease(sum);
this.increase(sum);
return "成功!";
}
catch{
return "失败!";
}
}
private void decrease(int sum){
SqlConnection con=new SqlConnection("server=.;database=store;uid=sa;pwd=12345678");
con.Open();
SqlCommand cmd=new SqlCommand("update aaa set money=money-"+sum.ToString()+"where account='A'",con);
cmd.ExecuteNonQuery();
con.Close();
}
private void increase(int sum)
{
SqlConnection con=new SqlConnection("server=.;database=store;uid=sa;pwd=12345678");
con.Open();
SqlCommand cmd=new SqlCommand("update aaa set money=money+"+sum.ToString()+"where account='B'",con);
cmd.ExecuteNonQuery();
con.Close();
}
验证a、b双方转帐
[WebMethod]
public string HelloWorld(string name)
{
return "Hello+name";
}
<form name="f1" method="post" action="http://localhost/WebServiceTest/Service1.asmx/HelloWorld">
<input type="text" name="name"><input type="submit"> <!--name="name"通过此传-->
</form>
[WebMethod(Description="获取库存")]
public DataSet getStore(){
SqlConnection con=new SqlConnection("server=.;database=store;uid=sa;pwd=12345678");
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("select * from store",con);
DataSet ds=new DataSet();
sda.Fill(ds,"store");
return ds;
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
WebServiceTest.Service1 ss=new WebServiceTest.Service1();
this.DataGrid1.DataSource=ss.getStore();
this.DataGrid1.DataBind();
}
[WebMethod]
public string AtoB(int sum){
try{
this.decrease(sum);
this.increase(sum);
return "成功!";
}
catch{
return "失败!";
}
}
private void decrease(int sum){
SqlConnection con=new SqlConnection("server=.;database=store;uid=sa;pwd=12345678");
con.Open();
SqlCommand cmd=new SqlCommand("update aaa set money=money-"+sum.ToString()+"where account='A'",con);
cmd.ExecuteNonQuery();
con.Close();
}
private void increase(int sum)
{
SqlConnection con=new SqlConnection("server=.;database=store;uid=sa;pwd=12345678");
con.Open();
SqlCommand cmd=new SqlCommand("update aaa set money=money+"+sum.ToString()+"where account='B'",con);
cmd.ExecuteNonQuery();
con.Close();
}
验证a、b双方转帐
- Asp.Net从零开始学-22
- 从零开始学ASP.NET
- Asp.net从零开始学-1
- Asp.net从零开始学-2
- Asp.net从零开始学-3
- Asp.net从零开始学-4
- Asp.Net从零开始学-5
- Asp.Net从零开始学-6
- Asp.Net从零开始学-7
- Asp.Net从零开始学-8
- Asp.Net从零开始学-9
- Asp.Net从零开始学-10
- Asp.Net从零开始学-11
- Asp.Net从零开始学-12
- Asp.Net从零开始学-13
- Asp.Net从零开始学-14
- Asp.Net从零开始学-15
- Asp.Net从零开始学-16
- 信息与计算科学专业应届毕业生的简历
- 字符数组初始化
- smart工作流管理系统自动生成的页面和数据的效果示意图
- MySQL入门
- 利用Socket进行Java网络编程
- Asp.Net从零开始学-22
- sql--Delete repeated items from a table
- 除了魁北克城和蒙特利尔以外的魁省
- C#资料整体目录
- 识别’低效执行’的SQL语句 -转贴来自http://dev.csdn.net/develop/article/20/20143.shtm
- 转 三步学会Java Socket编程
- ajax定时器
- 欧洲穷游儿在加拿大安省的一礼拜
- 人权和公民权宣言