How I can create connection with SQL database in C# WPF?
I have Created database in SQL server 2008. in C# WPF i want to feed data which can be stored in my SQL 2008 database kindly help me in making connection with SQL server 2008.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Santhakumar MunuswamyRank #128 · 17.3K reputationPosted Apr 25, 2015, 12:45 AM EDT
Refer
http://www.codeproject.com/Tips/362436/Data-binding-in-WPF-DataGrid-control
http://www.c-sharpcorner.com/UploadFile/deepak.sharma00/data-binding-in-wpf-datagrid-control-using-sql-server-databa/
Afzaal Ahmad ZeeshanRank #60 · 27.6K reputationPosted Apr 25, 2015, 12:50 AM EDT
- First of all get the connection string for your database. It contains the mechanism for connecting to your database, server name, database name and authentication methods.
- Secondly, reference to System.Data.SqlClient. It contains the classes and other methods required to work with SQL Server databases.
- Thirdly, use the functions to get the results from database and then update your user-interface.
This way you can get the data from your database, view the results on your WPF application. I have already sent an article to C# Corner team and I am waiting for it to be approved. Hopefully it gets approved soon so that I can provide a link of it to you too. :)Muhammad Shakeel3 reputationPosted Apr 28, 2015, 5:24 AM EDT
Using System.Data.SqlClient;
class DataBase
{
private string ConnectionString = string.Format("Data Source=({0});Initial Catalog = {1};Integrated Security={2}", DataSource,DataBaseName,IntegratedSecurity) ;
/*
DataSource means that your Sql server is installed on Current system or remote system.
if current system then it would be "Local"
DataBaseName means your database Name. eg "MySchoolDataBase"
IntegratedSecurity means your database security/password/ Write "SSPI" instead.
*/
}
USE MY API in attached, I use this in my Projects