Click to get Flash Player
Get Adobe Flash player

or try to enable JavaScript and reload the page

Friday 6 May 2011

SQL Database Connection -csharp


 using System;
    using System.Data.SqlClient;
  
  class ConnectToSqlConnection {
    static void Main(string[] args)  {
      String sConn = "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";

        String sSQL = "select name from Employee";

      SqlConnection oConn = new SqlConnection(sConn);
      oConn.Open();

      SqlCommand oCmd = new SqlCommand(sSQL, oConn);
      SqlDataAdapter da = new SqlDataAdapter();

      da.SelectCommand(sSql);
      
      }
    }
  }

// Integrated security must set to be 'true' at the place of SCPI if u wan to provide window authentication

No comments:

Post a Comment

thnx