Update SQL Server CE rows with dynamic data - c#

I am working on a solution where I track changes from a grid and to show all changes in a form to check the changes. so I have several DataRows where I know that the user did some modifications. and now I want to update the rows in my SQL Server CE database. But how? How can I update a single row in SQL Server CE?
The poblem is, that I cannot use objects because the data is dynamic. that means that I never know the structure of an "object" in my case. therefor I have to build a variable command for the insert. I think the simplest way would be to update only the changes of a row, but where can I get only the changes of a DataRow? the following information would be helpful:
columns where the changes made
values of each column and change
with this information I should be able to create a SQL command to update a single row, isn't it?
I also use the bulk insert from here http://sqlcebulkcopy.codeplex.com/
maybe I am wrong?!? any suggestions?
thanks,
tro

You can bind the data to a DataSet, and using DataGridView, you can automatically update the underlying table, wothout writing any SQL statments, see my SQL Server Compact Toolbox for sample code (on Codeplex)

Related

System.Data.SqlClient.SqlException (Invalid Column Name '...') after modifying database when using Data Source on a listbox

I just started developing my first application using Visual Studio. I have created my own SQL Server database and connected it to a listbox element using a Data Source which is working fine.
However I noticed that after modifying the Data Source (let's say removing a column) I get the error mentioned in the title, which makes perfect sense as obviously the column doesn't exist anymore. But how can I tell Visual Studio that it does not have to look for the removed column anymore?
After receiving the error, I only get directed to this line of code:
this.tableNameTableAdapter.Fill(this.dbNameDataSet.dbtable);
I can't really do anything with this. I've tried to look up the internet for several answers but I couldn't find someone who has encountered the same problem (probably because I used the wrong keywords).
Any advice? Thanks for helping me out!
Additional question: Is this called DataBinding?
You need to reconfigure the TableAdapter after any change in the schema:
configure-a-tableadapters-fill-method
Even better, make the changes in the TableAdapter first and they'll be reflected to the database:
Any changes that you make to the TableAdapter's main Fill method are reflected in the schema of the associated data table. For example, removing a column from the query in the main Fill method also removes the column from the associated data table. Additionally, removing the column from the main Fill method removes the column from any additional queries for that TableAdapter.

Are there ways to copy methods from one TableAdapter to another?

I've created a DataSet related with SQL server database. This DataSet has a set of tables with TableAdapters where I've written methods to access database data. Later I've moved my database to another server, changed a connection string and tried to update the DataSet. But the Wizard just adds copies of the tables with empty TableAdapters to the DataSet.
So now I want to copy the methods of original TableAdapters to the new ones and to delete original tables after. Can I do it? Or maybe someone show me another solution.
With many tries I've got the solution! It's pretty easy:
Open your DataSet.
Right-click on first table.
Click "Configure...".
Click "Done".
Repeat steps 3-4 with all of your tables.
If you got no errors your table is updated now!

Automatically create column in destination table based on source column in SSIS or in SQL

I have requirement to create automatically columns in sql server table using ssis or sql.(you can suggest)
Scenario is like this,
In ODBC Source table I have 10 columns.
Using SSIS transformations I am importing 10 columns data into my destination SQL server table.
On second day I have 12 columns in source.....(Here is the problem)
Now I need 12 columns in destination also and number of columns always increment everyday.
How can I handle this using any tool or code ....Please suggest.
Thanks in advance ...
You can create BIML and do automation using C# to generate ssis package.
More details are available at below link
Automatically generate SSIS package from BIML script
#Nick.McDermaid already said it, but adding columns dynamically to a table is a really bad design decision. For one thing, it'll cause no end of problems when you try to work with the data in the table. How will you know when a blank column means "unknown", means "no data in this load", or "this column didn't exist in the load"?

How to add / edit / delete an element in both the database and the listbox properly using a BindingSource

I'm currently coding a WinForm application with a MS SQL database in background. I made a ListBox diplaying all the rows of a table from my database using a BindingSource with Linq-To-SQL and I do not understand how I can delete a record from the table and automatically update the ListBox. Is it not the interest of the BindingSource, to report changes to the data ?
I'm just looking for advice, not a ready-made solution ;-)
Thanks you.
There is no live connection between the database and the application. The BindingSource is a link between the in-memory data cache and the UI. It knows nothing about the database. LINQ to SQL works by pulling data into the application from the database. The application has to initiate the request. The database doesn't push changes to the application because it has no idea what applications there are that may be using that data. There might be a single instance of a single application or hundreds of users of multiple applications.

visual studio DataSet designer with stored-procedures ? what is this icon

What does this icon mean is Visual studio, visual Data Set designer.
I have several stored procedures.
can you help me understand,
why the one on top of the list has a
small "check mark"
why I can't delete it if I need to.
This is not the case with the rest.
Why is this "special" ?
Thanks
Because that item contains the method(s) that define the schema of the table the TableAdapter is part of.
The default names are Fill and GetData. Looks like you renamed them.
Each table has a default query (The one on top with the check on it). When you dragged your tables in to the dataset to create the query, it wrote a SQL statement which it uses to schema your table. Keep that query simple, you might not actually use it in code, and you can always edit that query to update the table schema. In the picture you provided, your default query is actually a stored procedure.
Every time you open the default query it connects to your datasource and allows you to select new columns that weren't in there before. If you want to update your existing columns, delete all the columns out of the table before you attempt to open the query. When you save the query, your updated columns get added back.
Make sure your connection string has permissions to view column information.

Categories

Resources