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)
Related
In my application I'm allowing user to add/delete new fields to data base, so I need to find a best solution of my regular column add/update/delete problem in sql server database, I'm c#.net developer, and I usually work using Entity Framework. I have been googling this and came across EAV (Entity Attribute value) and then I found EAV Model Db Storage for .Net for c#.net.
Source code is provided and I went through it its good thing. but do we have a better solution of my problem, as I could not find any documentation on how to use it in any application(asp.net mvc, wpf, winforms, console app)
What if I do not want to combine traditional relational tables and entity-attribute-value(triplets) in same database?
I am new to EAV and not sure how should I handle this case.I will highly appreciate any response on it.
EDIT: I have found this: https://www.nrecosite.com/semantic_storage_net.aspx# but its not helping me out because there is no proper documentation. So I'm asking this particularly for c#.net development.
Thanks
I've made a local database for a C# project:
I know basic SQL commands, but haven't worked with databases in C#.
What I'd like to know specifically is:
How to read from the database (query)
How to add and update rows
The database only consists of 3 tables, so I don't think anything fancy is needed.
First, you should learn a bit about various technologies and APIs for connecting with a database.
The more traditional method is ADO.NET, which allows you to define connections and execute SQL queries or stored procedures very easily. I recommend digging up a basic tutorial on ADO.NET using Google, which may differ depending on what type of project you're creating (web app, console, WinForms, etc).
Now days, ORMs are becoming increasingly popular. They allow you to define your object model in code (such as every database table would be a class, and columns would be properties on that class) and bind to an existing database. To add a new row to a table, you'd just create an instance of a class and call a "Save" method when you're done.
The .NET framework has LINQ to SQL and the Entity Framework for this sort of pattern, both of which have plenty of tutorials online. An open source project I really like is Castle Active Record, which is built on top of NHibernate. It makes defining ORMs quite easy.
If you have specific questions about any of the above, don't hesitate to post a new question with more specific inquiries. Good luck!
Update:
I thought I'd also put in one last reference as it seems you might be interested in working with local database stores rather than building a client/server app. SQLite allows you to interact with local stores on the file system through SQL code. There's also a .NET binding maintained by the SQLite guys (which would in theory allow you to work with the other platforms I mentioned): http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki
You can use SQLCE.
This blog will give you a good start.
http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx
Here is a small tutorial that should be helpful to you.
You can make use of the SqlDataReader to read data
and the SqlCommand to Insert Update Delete rows from your tables.
http://www.dotnetperls.com/sqlclient
You could use it by adding following to your Startup.cs
services.AddDbContext<DemoDbContext>(options => options.UseSqlite("Filename=data.db"));
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.
I am working on a personal project as a way of learning more about C# and .NET, specifically creating an application that utilises a database (MS SQL Server 2008 in my case). Whilst I appreciate there isn't always a definitive "right" way of doing things, given the choice between using an old technology/idea or a new one, I would rather use the new one. For example, one of my aims for this project is to learn, or at least familiarise myself with, WPF rather than using WinForms as I have done in the past.
On that basis, I've been muddling around without a great deal of direction with regards to saving data to my database and retrieving it. So far I've managed to get both those working using TableAdapters but I feel like they are the "old" way of working (my basis for this is that they are listed under Visual Studio 2005 on MSDN). Firstly, am I correct in this assumption? If so, what are the newer methods of saving and retrieving data from a database? I would be grateful of any pros and cons each method offers.
I've Googled and searched MSDN extensively but I don't feel like I am using the correct search terms as I have only succeeded in confusing myself.
I have .NET 3.5, Visual Studio 2008 and Microsoft SQL Server 2008 at my disposal.
Any guidance would be much appreciated.
I would agree that TableAdapters, DataSets, DataTables, etc. are the "old" way of doing things.
The "new" way would be Linq-to-SQL, Entity Framework or NHibernate.
Personally, I like to use a combination of Linq-to-SQL along with plain old DBConnections, DataReaders and DTO's where needed.
If you would like a newer way of doing Database access in .NET, I would recommend looking into LINQ to SQL or the Entity Framework.
There are many many many different ways to retrieve data from SQL Server 2008 using .Net.
Table Adapters are not a bad way; they are core to the .Net Framework, easy to get started with and reasonably powerful, although they do not perform quite as well as other options and often require more memory.
Basically Table adapters are good if your data is structured the way you want to view it. If you want to view data in a different way to it is stored you can do this with a table adapter but you loose the ability to write back changes to the database, this is OK if you are just generating a report.
If you want to view and change the data and the data is not in the structure you want to view it you need entity framework so you can query the data to get it into a different format and still have the ability to write any changes back. This is what the call the data from the server the MV to the display the VM
I am, a beginner to databases, and am very inexperienced at programming generally. For a C# console app (I'm writing with VS Express), which after testing will have a UI added, I need to use a database to store its data.
Can someone tell me, or point me to, bare beginner's explanations, and pros and cons, of these database access methods so I can decide which I should use?:
SQLClient
ORM
OleDB
ODBC
ADO.NET
nHibernate
MS Enterprise Library
Quite the mix there ... first some explanations ...
1) SQL Client
An SQL client is an application that connects to a SQL Database for the purpose of querying / managing / working with the data in an SQL Database. (any program accessing a database, phpAdmin, SQLite Administrator, etc...).
2) ORM is object-relational mapping. Its a way to convert different types of data when data types are incompatible. Think about a car class that incorporates four instances of a tire class. This type of structure doesn't translate well directly to the types available in database design and may be a reason to use ORM. (To relate the objects (car, tires, etc..) into the plain database types (integer, float, blob, etc..)
3) OLE (pronounced Olay) DB Is the Microsoft method (API) for connecting to Database using COM. OLE DB is part of the MDAC Stack (grouping of MS technologies working together in a framework for data access).
4) ODBC is Open Database Connectivity and its an alternate API for for Database Management Systems (DBMS). Where OLE DB is a COM (Component Object Model) way to integrate with databases, ODBC aim's to be language independent.
5) ADO.NET is a set of base classes (API) for use in the .NET languages to connect to and communicate with Databases.
I would suggest starting with ADO.net for your C# background, OLE is typically for older (VB classic) applications, There is a good beginner tutorial here http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx
Don't let all the terminology scare you off, once you jump in and start tinkering you will understand all of the answeres provided better...
Best of Luck in your coding!! :-)
SQLClient, OleDB, ODBC are the DBMS Drivers/ADO.NET implementations of different DMBSs (err, hope that makes sense). For example, SQLClient is the ADO.NET implementation for connecting to a SQL Server database. The choice between these drivers is just which database you want to use. For a beginner, I would suggest SQL Server as you probably already have some version of that installed.
ORM is Object-Relational-Mapping. This is a code-based implementation of an auto-mapping between your code-based models, and your database that stores it. If you don't want to manually touch the database for the time being as you are learning, this is a good option - it is something useful for pros and beginners alike, as it allows you to not worry about the underlying database implementation, or writing CRUD (create, read, update, delete) functionality yourself. Take a look at ActiveRecord for .net (http://www.castleproject.org/activerecord/index.html)
If you are looking for an easy introduction to databases in C# you want to use LINQ and a data context.
Simply add a "Data Context" to your project. Double click the file to open the designer for the LINQ data context. Open the "Server Explorer" in visual studio (under View) and connect to your SQL Server. Using that you can drag and drop your tables onto the LINQ designer in visual studio.
Jump on google and have a look at using linq with a context to do work on your DB.
I'll jump in here with LINQ to say that it encourages you to write better database code, that doesn't pull the whole dataset out in one go and operate on it, you defer queries and you can benefit greatly from the functional infrastructure they've built upon it.
But this has a big learning curve, best way to do it is to try different kinds of code and see the ones that make sense to you.