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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Muhammad ShakeelPosted Apr 28, 2015, 9:24 AM
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
Afzaal Ahmad ZeeshanPosted Apr 25, 2015, 4:50 AM
- 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. :)Santhakumar MunuswamyPosted Apr 25, 2015, 4:45 AM
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/