I think this is what you are looking for.
String sql = "SELECT [UserId] FROM [UserProfiles] WHERE NOT [UserId] = 'CurrentUserId'";
string strCon = System.Web
.Configuration
.WebConfigurationManager
.ConnectionStrings["SocialSiteConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(strCon);
SqlCommand comm = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader nwReader = comm.ExecuteReader();
while (nwReader.Read())
{
int UserID = (int)nwReader["UserID"];
}
nwReader.Close();
conn.Close();
I have to say, however, that the general approach can use a lot of settings. First, you could at least start by simplifying access to your ConnectionString. For example, you can add the following to the Global.asax.cs file:
using System;
using System.Configuration;
public partial class Global : HttpApplication
{
public static string ConnectionString;
void Application_Start(object sender, EventArgs e)
{
ConnectionString = ConfigurationManager.ConnectionStrings["SocialSiteConnectionString"].ConnectionString;
}
...
}
Now, throughout the code, just open it using:
SqlConnection conn = new SqlConnection(Global.ConnectionString);
, , "". , :
using (BSDIQuery qry = new BSDIQuery())
{
SqlDataReader nwReader = qry.Command("SELECT...").ReturnReader();
while (nwReader.Read())
{
int UserID = (int)nwReader["UserID"];
}
nwReader.Close();
}
DAL. , , , "BSDIQuery" ( , ). , .