c# local database / dataset - c#

I'm new on C# and I want to have my data on a local database. The problem is I can't understand how to do it. I created a sgt.sdf (database) file and a sgtDataSet.xsd (dataset) but I don't seem to understand the relation between those two files. Can anyone explain me how to work properly with this?

If you are new to C# and learning it, so you should be able to start learning about databases, example databases on a SQL Server or likewise.
Or you could use a localDB if you don't want to setup a SQL Server.

If you wanna start with something less cnfusing, i sugest using an access database. Sdf databases are u reliable. They can be broken without even knowing.
When using access you will be using the OleDB code in C# it's almost the same as the other ones.
Hope it helped :)

Related

c# Service to copy data between two sql servers

I have two sql servers installed on my computer (SQL2008 EXPRESS) and also SQL2008 that comes with the specific software that we are using.
I need to make a service that runs all the time and at a specific time updates the non existing records in the SQL2008 EXPRESS from SQL2008.. can you suggest a way of doing this?
Currently the best thing I got is making a local copy in excel file, but that will result 365 excel files per year which I dont think is a good idea :)
p.s. sorry if my english is bad :)
You don't have to hand-craft your own software for that. There are 3rd party tools like OpenDbDiff or RedGate dbdiff to do that. These tools generate the differential sql that you can apply on your target database.
I'm confused when you mention Excel. What would Excel have anything to do with moving data from one SQL database to another?
The short answer is, if you need a C# service, then write a C# service that copies the data directly from one database to the other. The problem that you are trying to solve is not very clear.
Having said all that, and with my limited understanding of the problem, it sounds like what you need is a SQL job that is scheduled to run once a day that copies the data from one server to the other. Since it sounds like they are on separate instances, you'll just need to set up a linked server on either the source or destination database and either push or pull the data into the correct table(s).
EDIT:
Ok, so if a windows service is a requirement, that is perfectly acceptable. But, like I mentioned, you should forget about Excel. You wouldn't want to go from SQL->Excel->SQL if you have no other reason for the data to exist in Excel.
Here is some information on creating a windows service:
Easiest language for creating a Windows service
Here is a simple tutorial on accessing SQL in C#: http://www.codeproject.com/Articles/4416/Beginners-guide-to-accessing-SQL-Server-through-C
If you want a more formal solution (read: data access layer), I'd point you toward Entity Framework. The complexity of the project will probably be the driving factor on whether you just want to do SQL statements in your code vs. going with a full blown DAL.

Creating an SQL Database for Windows Forms Application

I'm still a little new to programming in C# and I'm a little puzzled about how to create a SQL database which will be accessible by many different computers over a mapped path connection. Can anyone suggest the best way to do this?
Many thanks.
I would caution you against using a shared file database over a mapped UNC path. There is a very good reason that database servers exist. I would recommend you try SQL Express 2012 if you are looking to save money and have only a small amount of data and a few users.
If you want to create a database using C# code here is a link http://www.codeproject.com/Articles/10213/Create-an-SQL-Server-Database-Using-Csharp. Otherwise you can just use the SQL Server management studio to create a new database - here's the link http://msdn.microsoft.com/en-us/library/ms186312%28v=sql.90%29.aspx.

How easy is it to change DB in a MVC3 project?

Basically I have made a MVC3 application that connects to and updates a database that exsists on a server. This database is a test one however, and when I roll out the project live I need it to connect to the actual database. My question is how hard would it be to change the project/application to point at this new database?
I used the database first method, and am aware I would need to change my connection string. I feel it is unlikely to be as simple as that.
Any help, tips or tutorials would be greatly appreciated.
As long as the database structures are the same, it is just as simple as that.
You just need to change the connection string.
Additionaly if you would like to deploy 2 versions of the website, each using it's own connection strings (for example for developpement and production) you can create 2 web.config files. Refer to this link SO question
It shouldn't be that hard. You just need to make sure that the database that you are working on now and the database that you are changing to are equal in table names and column names otherwise you are going to have configure it to use the new database tables and columns.

how to start using db in .NET platform

i want the most simple example from scratch how to
open new db
populate it with one table
connect and open it to simple select query
I have been looking for sothing relvant in the last 2 days please help me i neede just the basic
I am using visual studio 2008/2010 and i know mysql but dont know how to use VS for DB
I would prefer example using ADO.NET
There are tons of ways to do that.
Have a look at ADO.NET, LINQ2SQL, Entity Framework, NHibernate ....
You can find a lot of examples in internet.
If you want to stick with MySQL and C#, this PDF will walk you through the process.
http://dev.mysql.com/tech-resources/articles/Beginning_MYSQL_5_with_Visual_Studio.NET_2005.pdf
If you're just getting a start on things, check out the ASP.Net tutorial on building a Data Access Layer using TableAdapters. This is a great start because it gives you a nice drag and drop type interface for a lot of things, in addition to giving you strongly typed data. All the concepts of data adapters and connection strings are there, just managed by the object it creates.
The nice thing about the Table Adapters is that it leverages ADO.Net so you simply have to replace your DataAdapter with SQL, MySQL, SQLite adapter you need.
Once you get the hang of that, you can move into integrating your Business layer as well through the LINQ to SQL tutorials.
I've been in the same situation, just finding my feet with ADO and .Net database handling in Visual Studio. Up to now I'm finding that some of the most useful guides are:
Walkthrough of getting started with SQL Server Compact
Tutorial on Linq-to-SQL
The guide to using table adapters to synchronise the DataSet with the database
hi there my personal preference would be to use pgsql server and npgsql.dll. the link to
pgsql is here and just google npgsql.
these are the best documented fastest and easiest to use databases i have found (that is an opinion open to suggestions)

Easiest way to use SQL in a C# application?

I'm making an application in C# (with Express Edition) for which I would like to add some SQL functionality so that the user can query a database. I don't care how or where I store the database. I can store it in a DataTable or a bi-dimensional array or any kind of file. But I want the user to be able to SQL-query it. Apparently this should be quite simple since the .net seems to be full of database libraries and stuff. I was thinking about downloading MySQL and see if I can connect it to my application. I guess if I want to distribute my application then the user would need to download MySQL as well, which is not a big deal but would be great if I can avoid it. Anyway, for now I would like to start working on my program ASAP, so whatever is the easiest way to do what I want, even if it's not distributable, (but if it is then that's even better), will be good. Thanks in advance.
There are embeddable databases. SQL Server Compact Edition and SQLite are common ones. You can execute queries against these just as you can MySQL or SQL Server.
SQLite (.NET)
SQL Server Compact
You can use most popular databases with .NET. SQL Server, Oracle, MySQL, etc. But you're gonna need drivers of each. So, I'd suggest using SQL Server Express Edition to you to get started.
Then you can easily use SqlConnection and SqlCommand classes to connect and execute queries.
You could use a dbml file in your project and link it to your sql database and then run a sql statement using Linq2SQL documented here
I would look at using and embedded database that you can distribute with your application. SQLite is a very good option. You can then use a free ADO.Net library like System.Data.SQLite for data access. It also provides design time support for Visual Studio.
You can use LINQ to Objects or LINQ to Datasets to run LINQ queries with no database whatsoever. You can't use a bi-dimensional array, but you can use a List<> of objects with properties as a LINQ context.
From your question it sounds like your application, like most applications, may need to store the data for later use: that's where a database will come in handy. .NET Datasets have built in support for persistence to an XML file if your data storage requirements are simple enough to use that. .NET also supports persistence for objects, but you may find that using a database is the simplest solution, especially if you require multi-user access and editing.

Categories

Resources