如何执行两个操作,例如在单个按钮上进行插入和更新保存 [英] how perform both operations such as inserting and updating on a single button save

查看:194
本文介绍了如何执行两个操作,例如在单个按钮上进行插入和更新保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想执行两个操作,例如在单个按钮保存上插入和更新.?


任何建议..?

解决方案

是的.但是您将需要确定正在执行的操作.例如,如果您在输入表单中新输入了数据,则显然要插入它.在代码中设置标记"INSERT".
编辑记录时,您需要对其进行更新,同时将其设置为与"UPDATE"相同的标志.

示例代码:

 字符串 私有 strflag = 字符串.空;
受保护的 无效 Button_Click(对象发​​件人,EventArgs e)
{
   如果(strflag.toUpper()== " )
   {
      // 插入代码
   }
   其他 如果(strflag.toUpper()== " 更新")
   {
      // 更新代码
   }
} 


 受保护的 无效 btnSave_Update_Click(对象发​​件人,EventArgs e)
{
// 您的插入"服务器端代码


// 更新"的服务器端代码
} 


hi

I want to perform both operations such as inserting and updating on a single button save.?


any suggestions..?

解决方案

Yes it is possible. But you would require to identify which operation is being performed. Such as if you have newly entered data in the input form, you obviously want to insert it. Set a flag in the code saying "INSERT".
When you are editing a record, you would require to update it, while doing this, set the same flag as "UPDATE".

Sample Code:

string private strflag = string.Empty;
protected void Button_Click(object sender, EventArgs e) 
{
   if(strflag.toUpper() == "INSERT")
   {
      //Insert code
   }
   else if(strflag.toUpper() == "UPDATE")
   {
      //Update code
   }   
}


protected void btnSave_Update_Click(object sender, EventArgs e)
{
//Your server side code for 'Insert'


//Your server side code for 'Update'
}


这篇关于如何执行两个操作,例如在单个按钮上进行插入和更新保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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