//On a mojo Web Page, this will get you your connection string like this
private static string GetConnectionString()
{
return ConfigurationManager.AppSettings["MSSQLConnectionString"];
}
//I'm a stored procedure type guy
//and in mojoPortal I use the mojoPortal.Data.SqlParameterHelper in this example
public static int k_proc_keys_GetNextKeyByField(string fieldName)
{
SqlParameterHelper sph = new SqlParameterHelper(GetConnectionString(), "k_proc_keys_GetNextKeyByField", 2);
sph.DefineSqlParameter("@FieldName", SqlDbType.NVarChar, 50, ParameterDirection.Input, fieldName);
sph.DefineSqlParameter("@NextKey", SqlDbType.Int, ParameterDirection.Output, null);
sph.ExecuteNonQuery();
int newID = Convert.ToInt32(sph.Parameters[1].Value);
return newID;
}
//Outside of mojoPortal in console apps I use code like this to return a DataTable
public static DataTable ReadUrlList()
{
SqlConnection kickerConnection = new SqlConnection();
kickerConnection.ConnectionString = @"Server=.\SQLEXPRESS;Database=mojoPortal_database;UID=mojouser;PWD=mojopassword;";
DataTable UrlsDataTable = new DataTable();
string query = "SELECT StuffGuid, StuffName from myStuff Where IsValid = 1 OR ((EndUtc Is Null) OR (EndUtc > @EndUtc))";
SqlCommand cmd = new SqlCommand(query, kickerConnection);
cmd.Parameters.Add("@EndUtc", SqlDbType.DateTime);
cmd.Parameters["@EndUtc"].Value = DateTime.Now;
SqlDataAdapter urlAdapter = new SqlDataAdapter(cmd);
kickerConnection.Open();
urlAdapter.Fill(myDataTable);
kickerConnection.Close();
urlAdapter.Dispose();
return myDataTable;
}
Actually the first bit of code at the top for your connection string along with a gazillion C# database examples from a Google search will get you data.
Rick