Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 24-Apr-10 1:51am
v3

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]
 
Share this answer
 
v2
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.
 
Share this answer
 
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 ?!
 
Share this answer
 
Please don't push 'answer' to ask more questions, edit your post.

This code connects to your database and runs a SQL command. There is no earthly reason for it not to work. If you look at your database while the app is running, you should see if the data is there. If it's not there, why is it OK in your UI until you close the form ? The fact it shows OK, if your code is written properly, means it's placed in the DB and is lost when you restart, which means the DB is being reset.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900