如何在dot net中通过C Sharp编码刷新数据库
我正在使用c Sharp语言在dot net中开发一个Windows项目,后端是sql server数据库。
我正在做的是有一个 SQL 查询在表中插入数据,如下所示。
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source = ...........";
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO TableName(column1, column2) VALUES(txtBox1, txtBox2)", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
Dataset ds = new Dataset();
现在,我在这里面临的问题是,当我尝试使用 Microsoft Report Viewer 在另一个 Windows 窗体中访问该表时。然后,新插入的数据将无法访问,因为它需要刷新数据库。 请告诉我如何解决这个问题。 提前致谢 迪帕克
I am developing a windows project in dot net using c sharp language and the back-end is sql server database.
What I am doing is that there is a SQL query to insert data in the table as
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source = ...........";
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO TableName(column1, column2) VALUES(txtBox1, txtBox2)", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
Dataset ds = new Dataset();
Now, what problem I am facing here is that when I try to access this table in another windows form using Microsoft Report Viewer. Then, there the data newly inserted is not accessible since it needs the database to be refreshed.
Please tell me how can I resolve this problem.
Thanks in advance
Deepak
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不需要刷新它,只需从数据库请求它并提交事务(如果您正在使用它)。但是,如果您想在表单之间共享数据,请使用注册表模式来实现此目的。
注册表是为您保存数据的类,您可以从任何地方访问它,但不能使用静态变量和方法。
如果您更改一种表单中的数据,则所有表单都将具有更新的数据。
i don't think that you need to refresh it, just request it from db and commit transaction if you are using it. But if you want to share data between your forms use Registry pattern to achieve this.
Registry is class which will hold data for you, and you can access it from anywhere but use static variables and methods.
And if you change data from one form all forms will have updated data.
似乎有很多错误,将此行更改
为
并且您的命令从未在数据库上执行
It seems there are many error,change this line
to
and your command never executed on database