OK, dll can be any execution file, you can create a project/website/class library/web application. So here i am just explaining dll of Class Library
1) Click on file menu -> New-> Project -> Class Library (you can select your language VB or C#)
2) name it SampleDll
3) there would be class1.cs (You can change class name as SampleClass as i did in following example)
4) write any database related code here.
Add two namespace to connect with database (I am taking here sqlclient for sql server)
using System.Data;
using System.Data.SqlClient;
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ClassLibrary1
{
public class SampleClass
{
SqlConnection conn = null;
SqlCommand cmd = null;
public bool RunProcedure()
{
try
{
conn = new SqlConnection("Server=(local);DataBase=Northwind;Integrated Security=SSPI");
conn.Open();
cmd = new SqlCommand();
cmd.CommandText = "SampleStoredProcedure"; //
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
return true;
}
catch (Exception objEx)
{
throw objEx;
}
finally
{
if (conn!=null)
{
conn.Close();
conn = null;
}
if (cmd != null)
{
cmd = null;
}
}
}
}
}
now build project in release mode.
Go to your project folder->bin folder->Release Folder-> there would be a dll
Now you can use it as private of public assembly.
Thanks,
Rajni Shekhar
Jerome, if this helps please login to Mark As Answer. | Alert Moderator