1. An example of a dll file to call data from a sql database
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data.Common;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Net;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Principal;
using System.Text.RegularExpressions;
using System.Text;
using Microsoft.VisualBasic;
using System.Web;
using System.Xml;
namespace TestLibrary1
{
public class DataBaseDll3
{
public DataSet GetData1(string cmdText)
{
DataSet dt = new DataSet("Test");
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LIVE"].ConnectionString))
{
da.SelectCommand = con.CreateCommand();
da.SelectCommand.CommandType = CommandType.Text;
da.SelectCommand.CommandText = cmdText;
da.SelectCommand.Connection = con;
try
{
con.Open();
da.Fill(dt);
con.Close();
}
catch (Exception ec)
{ }
finally
{
con.Close();
}
}
return dt;
}
}
DON'T FORGET TO ADD THE CONNECTION STRING IN THE WEB.CONFIG FILE IN THE DLL
Then to call the result in the Code Behind..
ADD
using
Add the .dll file through the Reference Folder in Visual Studio
Use Browse and find the file in the bin/debug folder.
The add the follow code to call the DataSet .dll result...
DataBaseDll3 db2 = new DataBaseDll3();
Global.ds = db2.GetData1("Select GetDate();");
string test2 = Global.ds.Tables[0].Rows[0][0].ToString();