更新数据库获胜应用程序出现问题. VB.net [英] Problem With Update Data Base win app. VB.net

查看:72
本文介绍了更新数据库获胜应用程序出现问题. VB.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新VB.net应用程序中的SQL数据库时遇到问题
每次我使用更新或添加新行功能
更改将一直保留,直到我关闭发件人"
当我检查数据库时,没有更新
就像更改是临时性的东西一样,而不是保存在真实的数据库中

1)这是我的联系

Dim str As String = "Data Source= .\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"


数据库类型基于服务的SQL数据"

2)这是我的添加功能

 Sub Add_Info()
   
        Dim Con As New SqlConnection(Str)
        Dim sql As String = "insert into Test  values (@id , @n, @t)"
        Dim com As New SqlCommand(sql, Con)
        com.Parameters.Add("@id", SqlDbType.Int).Value = Count() + 1
        com.Parameters.Add("@n", SqlDbType.NVarChar).Value = "test"
        com.Parameters.Add("@t", SqlDbType.NVarChar).Value = "old1"
        Con.Open()
        Dim x As Integer = com.ExecuteNonQuery()
        Con.Close()
        Con.Dispose()
        com.Dispose()
        com = Nothing
End Sub



我是VS中的Ruining应用.
复制到输出目录"属性的值是什么?
如果您的意思是数据库的属性,那是正确的
它是始终复制"
如果将其更改为不复制,则会出现错误消息无法访问数据".

解决方案

我猜您是在VS中运行应用程序.

解决方案

br/> 复制到输出目录"属性的值是什么?
如果是始终复制"或如果更新则复制",则应在数据库的bin目录中查找,而不是在项目中查找数据.


如果将属性设置为如果更新则复制",则只有在更改设计或添加值时,该属性才会复制到垃圾箱.
您也可以手动将数据库复制到调试或发布目录.
您应该可以使用数据库浏览器打开它
[/EDIT]


如果您重新绑定到数据源并看到更改,直到重新启动,答案必须是在运行程序时正在重置数据库.例如,正在从另一个位置复制mdb文件并覆盖更改后的数据库.

您的ID列应该是一个身份,应该分配自己的身份,而不是被计算出来.


感谢4 ur回答克里斯蒂安·格劳斯" ...
问题是即使重启后数据库也不会更新
我将这个Add函数与asp.net中的mdb数据一起使用,它的工作 Fine
使用 win应用程序会出现问题.
我认为数据集或绑定源已更新,但未更新实际数据源
提交数据并将其保存在实际数据源中有任何帮助吗?!


I Have a Problem with Update my SQL Data Base In VB.net Application
each time I use a update or and Add new row Function
the change remain only until I close the From
And When I check with the database there is no update
Like the change is hold on temp thing and not save in the real data base

1)This is my connection

Dim str As String = "Data Source= .\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"


Data Base type "Service-Base SQL Data"

2)This my Add Function

 Sub Add_Info()
   
        Dim Con As New SqlConnection(Str)
        Dim sql As String = "insert into Test  values (@id , @n, @t)"
        Dim com As New SqlCommand(sql, Con)
        com.Parameters.Add("@id", SqlDbType.Int).Value = Count() + 1
        com.Parameters.Add("@n", SqlDbType.NVarChar).Value = "test"
        com.Parameters.Add("@t", SqlDbType.NVarChar).Value = "old1"
        Con.Open()
        Dim x As Integer = com.ExecuteNonQuery()
        Con.Close()
        Con.Dispose()
        com.Dispose()
        com = Nothing
End Sub



I''m Ruining app in VS.
the value of "Copy to output directory" property?
If u mean property of the Data-Base then that is right
it''s "Copy always"
If I change it to not copy I got an error msg of "cant access the data"
How can I View the data in Bin and see the data while My app still in the VS environment?

解决方案

I guess you are running your app from within VS.
What the value of "Copy to output directory" property?
If it''s "Copy always" or "Copy if newer" you should look in the bin-directory for your DB, not in your project for the data.

[EDIT]
if you set the property to "Copy if newer" it will be copied to the bin only when you change the design or add values.
You could also manually copy the DB to the debug or release dir.
You should be able to open it with database explorer
[/EDIT]


If you''re rebinding to your data source and seeing the changes until you restart, the answer must be that your database is being reset when you run your program, for example, an mdb file is being copied from another location and writing over your changed DB.

Your ID column should be an identity, it should assign itself, not be calculated.


Thanx 4 ur Answer "Christian Graus"...
The Problem is the Data Base don''t Updated not even after restart
I use this Add function with mdb data in asp.net and It''s work Fine
The problem Appears with using win app.
I think that the data-set or the binding source is updated but not the actual data source
Any help to Submit data and save it in the actual data source ?!


这篇关于更新数据库获胜应用程序出现问题. VB.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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