I am simply writing an INSERT query to insert values into the table, when I click the submit button the code runs successfully, I don't get any error.
But when I look into the table it shows no data i.e the table is not updated. I don't know why it's happening. Can anyone suggest me.
thank you
I had the same problem if you are using c# windows application probably you have two different data base connection one updated and another still not updated so check your connections and if you are using sql express your database might be replicated in you debug directory so check your debuge folder or run your application from executable file.
Related
I have made a program with a simple SQL Server .mdf database file.
First: I have connected to the database using SqlConnection and tried to insert some data using SqlCommand. The ExecuteNonQuery returns the number of affected rows successfully for example 1 or 2 ... etc.
But when I use Server Explorer to view the data of the table, there is nothing inserted!?
Then I have used model entity object and DataSource. On SaveChanges function I get also the number of affected rows successfully, but there is no data inserted in Table on viewing it.
When I make a query using Server Explorer, the data will be inserted successfully and I can view it!!? Can you please help me to solve this problem?
thank you marc_s, you gave me a hint "ConnectionString". As I created a database mdf with server explorer, I realized now, there is two mdf files created. One is located in base folder of project and the other located in bin/debug folder. I don't why there is two of them, howerver it solved my problem. Thanks
I downloaded source code of an ASP.NET MVC book and it looks this, I can see the table but I need to enter some data in it so it can show them to me
Where should I go to enter data?
While you should actually do this in SQL Server Management Studio, Visual Studio does offer you some support to deal with data. To do so, Open Server Explorer (Ctrl+Alt+S) in VS. Create a data connection, if it doesnt exist already to the DB in question by right clicking on Data Connection and click on Add Connection. Since you downloaded the source code for exercises, there is a good chance that they already created one for you. Once you have a connection to your desired database, you will be able to see database object under that including tables. To add data to a table, right click on that table and click on Show Table Data. You can then go to individual cells and enter data. Hitting enter should submit the data change to SQL Server.
Hope this helps..
So I have a database filled with values already. It works fine, until I start to query any values I have added into it. It just won't work.
I'm using a project on Visual Studio creating a Web Form, while the database connection, as well as the add, update, and delete methods, are stored in a DLL that I referenced.
The adding works, and so does the updating. I can see it in the database through the server explorer, but I cannot query what I am seeing. I tried querying values I did not add, and it works. When I query the rows I added, it won't work.
Let me know if you need anymore information. I have no idea what's going on.
I've encountered a similar issue and the catch to it was that it was actually using another database. I'd recommend you check with SQL Server Management Studio and make sure you're using the correct database and also have a look in Webconfig.
I have created update, delete and edit queries in Linq2SQL. Whensoever I run the program it automatically creates a duplicate database of present database and performing changes to it.
I tried to delete it but whenever program run it creates new database and perform changes to it.
Please help me to solve this problem fast.
In that case, You have created duplicate database with same name hence whenever you delete the database from server explorer, it get deleted but again start next time it create itself because it get recover data from App code .
So, for this you need to delete App Code showing on solution explorer but of working project. This will ruin the problem of duplication of database next time you start.
I am using a SQL Server Compact database for a project I am working on and have been having a hard time trying to insert data to the database.
My insert statement and everything is working fine and data gets inserted too and I can even do searches for the inserted data (while in the application).
The problem I am having is when I quit and re-run the application, it seems that the data was not inserted into the database and the tables are empty too.
Can anyone let me know where I am going wrong with this?
Thanks
Could it be that the SDF file is overwritten with an empty version whenever you rebuild/run the application?
As Thorsten pointed out, check the Build Action on your SDF file.