Fully depends on the database, if it's SQL Server you need to have a connection string in the web.config:
PHP Code:
<add name="LocalSqlServer" connectionString="data source=xx;initial catalog=xx;Integrated Security=SSPI;"/>
then example:
PHP Code:
using System.Data.SqlClient;
System.Data.SqlClient.SqlConnection cn;
this.cn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
cmd.Connection = this.cn;
cmd.CommandText = "SELECT kwID FROM xx WHERE userID='" + this.UserID + "'";
cn.Open();
dr = cmd.ExecuteReader();
dr.Read(); // We only need a single Read Run here cuz we want to get the oldest result ~
kwID = dr["kwID"].ToString();
dr.Close();
hth