在C#中由其他用户刷新数据库中数据更改的前端

编程入门 行业动态 更新时间:2024-10-27 01:24:47
本文介绍了在C#中由其他用户刷新数据库中数据更改的前端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用C#作为前端,有多个用户,它与Ms Sql Server 2008连接。我的问题是,如果一个用户使用更新选项更改数据。如何在不使用Select *命令或sda.fill的情况下,其他用户如何看到该更新语句的影响?我的表中有成千上万的记录,这需要花费太多时间来重新填充。 这是我用来更新数据的代码。

I am using C# as Front End with multiple users, which is connected with Ms Sql Server 2008. My Question is, If one user changes the data using an update option. how can other user see the impact of that update statement without using Select * command or sda.fill? I have thousands of records in my table which takes too much time on refill. Here is code i am using to update data.

MyGlobalVariables.bsInc.EndEdit(); MyGlobalVariables.con.Open(); MyGlobalVariables.CmdString = "Update Increment set IncAmount=" + Convert.ToInt32(txtInc.Text) + ", EditedBy='"+MyGlobalVariables.MyUname+"', editedOn=sysdatetime() where IncYear=" + Convert.ToInt16(cmbIncYear.Text) + " and EmpCode='" + MyGlobalVariables.MyEmpCode + "'"; MyGlobalVariables.cmd = new SqlCommand(MyGlobalVariables.CmdString, MyGlobalVariables.con); MyGlobalVariables.cmd.ExecuteNonQuery(); MyGlobalVariables.con.Close(); MyGlobalVariables.ds.Tables["Increment"].Rows[MyGlobalVariables.bsInc.Position].AcceptChanges(); MyGlobalVariables.MyParentForm.lblProg.Text = "Record Updated Successfully.";

推荐答案

使用 SqlDependency类 [ ^ ]。 请参阅: 使用SqlDependency进行数据更改事件 [ ^ ] 使用SqlDependency和SqlCacheDependency查询通知 [ ^ ] BTW:您的代码是 Sql Injection [ ^ ]易受攻击。请参考:如何:防止ASP.NET中的SQL注入 [ ^ ] Use SqlDependency class[^]. See: Using SqlDependency for data change events[^] Query Notification using SqlDependency and SqlCacheDependency[^] BTW: your code is Sql Injection[^] vulnerable. Please refer this: How To: Protect From SQL Injection in ASP.NET[^]

通过Allah Almighty的Grace,我找到了解决问题的方法。 这是插入过程后的我的代码。 By the Grace of Allah Almighty I have found the solution of my problem. Here is My Code after Insert Process. SqlDataAdapter sdaTemp = new SqlDataAdapter(); DataTable dtTemp = new DataTable(); MyGlobalVariables.con.Open(); sdaTemp = new SqlDataAdapter("Select * from Increment where ecode=(select MAX(ecode) from Increment) and UserID='"+MyGlobalVariables.MyUid+"'", MyGlobalVariables.con); MyGlobalVariables.con.Close(); sdaTemp.Fill(dtTemp); MyGlobalVariables.dtInc.Merge(dtTemp); MyGlobalVariables.dtInc.AcceptChanges(); MyGlobalVariables.bsInc.MoveLast();

感谢每个人的建议。

Thanks every body for your suggestions.

更多推荐

在C#中由其他用户刷新数据库中数据更改的前端

本文发布于:2023-10-20 09:12:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1510545.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:其他用户   数据库中   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!