Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
i wanna to connect my c# window forms with my ms sql database in an object oriented way /dynamically/ by creating classes how can ido this please help me by giving step by step procedures if you have a source code related to this or any free download books are highly wanted.

thank U for ur help
Posted

Try this: C# connection sql[^]
 
Share this answer
 
public DataSet ConnectExample()
{
   try
   {
      string theConnectionString = @"Server=" + SERVER + ";Database=" +
      DatabaseName + ";User ID=" + UserName + ";Password=" + Password + 
      ";Trusted_Connection=False;";
      
      //The SQL Statement
      string theSQL = "SELECT * FROM ExampleDatabase";

      //Create Connection
      SqlConnection thisConnection = new SqlConnection(theConnectionString);

      //Create data adapter
      SqlDataAdapter theDataAdapter = new SqlDataAdapter(theSQL, thisConnection);

      //Create DataSet to contain related data tables, rows, and columns
      DataSet thisDataSet = new DataSet();

      //Fill DataSet using query defined previously for DataAdapter
      theDataAdapter.Fill(thisDataSet, "ExampleDB");

      //Close Connection
      thisConnection.Close();

      return thisDataSet;
   }
   catch (Exception ex)
   {
      return null;
   }
}
 
Share this answer
 
v3
you can use Data Access Application Block for .NET! it is very powerful.

http://www.microsoft.com/china/MSDN/library/EnterpriseDevelopment/BuildDistApp/Vsdnbdadaab_rm.mspx?mfr=true[^]
 
Share this answer
 
This is covered by just about every book on C#. There are also many, many online resources for this. Rather than wait for an answer, look it up.
 
Share this answer
 
Try learning LINQ to SQL, Microsoft ADO.NET Entity Framework, NHibernate, Subsonic. There are lot of technologies/options available for us to do ORM in C#.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900