如何在asp.net中使用WebSevices更新数据 [英] How to Update data using WebSevices in asp.net

查看:86
本文介绍了如何在asp.net中使用WebSevices更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#命令对象在Asp.Net Web服务中进行更新操作将sql放入您的代码中,方法如下:

 字符串查询= 字符串 .Format( 更新mytable SET col1 ='{0}',col2 = {1} ....其中id = {3}", mystringvalue,myintegervalue,myIDValue);
SqlConnection连接=  SqlConnection(myconnectionstring)
connection.Open();
SqlCommand cmd =  SQlCommand(查询,连接);
cmd.CommandType = CommandType.Text
 int  rowAffected = cmd.ExecuteNonQuery()
connection.Close(); 



上面的代码是在我的脑海中键入的,因此可能需要进行调整.它还不包含任何异常处理,因为我想给其他人一个机会,让他们询问不可避免的问题,以了解代码为何会失败,从而获得声望点.最后,我提供的所有信息都可以通过最简单的Google搜索轻松地在Google上找到.


How to do Update operation in Asp.Net WebSevices using C# Command object

解决方案

You *should* do it via a stored procedure, but if you insist on putting the sql into your code, do it this way:

string query = string.Format("UPDATE mytable SET col1='{0}', col2={1}.... where id={3}", mystringvalue, myintegervalue, myIDValue);
SqlConnection connection = new SqlConnection(myconnectionstring)
connection.Open();
SqlCommand cmd = new SQlCommand(query, connection);
cmd.CommandType=CommandType.Text
int rowAffected = cmd.ExecuteNonQuery()
connection.Close();



The code above was typed off the top of my head, so it may need to be tweaked. It also doesn''t include any exception handling because i want to give someone else a chance to get reputation points for asking the inevitable questions you''ll have about why your code fails. Finally, ALL of the info I''ve provided is easily located on Google with the simplest of google searches.


这篇关于如何在asp.net中使用WebSevices更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆