Tuesday, February 10, 2009
Cache
Cache.Insert("KeyValue", someValue, null, DateTime.Now.AddMinutes(15), System.Web.Caching.Cache.NoSlidingExpiration);
Thursday, June 05, 2008
Display a ToolTip for a DataGrid Cell
private void dataGrid1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
try
{
DataGrid.HitTestInfo hti = dataGrid1.HitTest(e.X,e.Y);
if(hti.Type == DataGrid.HitTestType.Cell)
{
toolTip1.SetToolTip(dataGrid1, dataGrid1[hti.Row, hti.Column].ToString());
}
}
catch{}
}
{
try
{
DataGrid.HitTestInfo hti = dataGrid1.HitTest(e.X,e.Y);
if(hti.Type == DataGrid.HitTestType.Cell)
{
toolTip1.SetToolTip(dataGrid1, dataGrid1[hti.Row, hti.Column].ToString());
}
}
catch{}
}
Thursday, May 08, 2008
more SQL
// This example needs the
// System.Data.SqlClient library
#region Building the connection string
string Server = "localhost";
string Username = "my_username";
string Password = "my_password";
string Database = "my_database";
string ConnectionString = "Data Source=" + Server + ";";
ConnectionString += "User ID=" + Username + ";";
ConnectionString += "Password=" + Password + ";";
ConnectionString += "Initial Catalog=" + Database;
#endregion
#region Try to establish a connection to the database
SqlConnection SQLConnection = new SqlConnection();
try
{
SQLConnection.ConnectionString = ConnectionString;
SQLConnection.Open();
// You can get the server version
// SQLConnection.ServerVersion
}
catch (Exception Ex)
{
// Try to close the connection
if (SQLConnection != null)
SQLConnection.Dispose();
// Create a (useful) error message
string ErrorMessage = "A error occurred while trying to connect to the server.";
ErrorMessage += Environment.NewLine;
ErrorMessage += Environment.NewLine;
ErrorMessage += Ex.Message;
// Show error message (this = the parent Form object)
MessageBox.Show(this, ErrorMessage, "Connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
// Stop here
return;
}
#endregion
#region Execute a SQL query
string SQLStatement = "SELECT * FROM ExampleTable";
// Create a SqlDataAdapter to get the results as DataTable
SqlDataAdapter SQLDataAdapter = new SqlDataAdapter(SQLStatement, SQLConnection);
// Create a new DataTable
DataTable dtResult = new DataTable();
// Fill the DataTable with the result of the SQL statement
SQLDataAdapter.Fill(dtResult);
// Loop through all entries
foreach (DataRow drRow in dtResult.Rows)
{
// Show a message box with the content of
// the "Name" column
MessageBox.Show(drRow["Name"].ToString());
}
// We don't need the data adapter any more
SQLDataAdapter.Dispose();
#endregion
#region Close the database link
SQLConnection.Close();
SQLConnection.Dispose();
#endregion
// System.Data.SqlClient library
#region Building the connection string
string Server = "localhost";
string Username = "my_username";
string Password = "my_password";
string Database = "my_database";
string ConnectionString = "Data Source=" + Server + ";";
ConnectionString += "User ID=" + Username + ";";
ConnectionString += "Password=" + Password + ";";
ConnectionString += "Initial Catalog=" + Database;
#endregion
#region Try to establish a connection to the database
SqlConnection SQLConnection = new SqlConnection();
try
{
SQLConnection.ConnectionString = ConnectionString;
SQLConnection.Open();
// You can get the server version
// SQLConnection.ServerVersion
}
catch (Exception Ex)
{
// Try to close the connection
if (SQLConnection != null)
SQLConnection.Dispose();
// Create a (useful) error message
string ErrorMessage = "A error occurred while trying to connect to the server.";
ErrorMessage += Environment.NewLine;
ErrorMessage += Environment.NewLine;
ErrorMessage += Ex.Message;
// Show error message (this = the parent Form object)
MessageBox.Show(this, ErrorMessage, "Connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
// Stop here
return;
}
#endregion
#region Execute a SQL query
string SQLStatement = "SELECT * FROM ExampleTable";
// Create a SqlDataAdapter to get the results as DataTable
SqlDataAdapter SQLDataAdapter = new SqlDataAdapter(SQLStatement, SQLConnection);
// Create a new DataTable
DataTable dtResult = new DataTable();
// Fill the DataTable with the result of the SQL statement
SQLDataAdapter.Fill(dtResult);
// Loop through all entries
foreach (DataRow drRow in dtResult.Rows)
{
// Show a message box with the content of
// the "Name" column
MessageBox.Show(drRow["Name"].ToString());
}
// We don't need the data adapter any more
SQLDataAdapter.Dispose();
#endregion
#region Close the database link
SQLConnection.Close();
SQLConnection.Dispose();
#endregion
Friday, April 18, 2008
SQLDataReader
public static SqlDataReader Title()
{
SqlConnection connection = ConnectionManager.GetConnection();
var command = new SqlCommand("StoredProcedure", connection);
command.CommandType = CommandType.StoredProcedure;
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
return reader;
}
{
SqlConnection connection = ConnectionManager.GetConnection();
var command = new SqlCommand("StoredProcedure", connection);
command.CommandType = CommandType.StoredProcedure;
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
return reader;
}
Saturday, January 19, 2008
Linear interpolation, C#
static double interpolate( double x0, double y0, double x1, double y1, double x )
{
return y0*(x - x1)/(x0 - x1) + y1*(x - x0)/(x1 - x0);
}
{
return y0*(x - x1)/(x0 - x1) + y1*(x - x0)/(x1 - x0);
}
Thursday, April 19, 2007
Monday, March 19, 2007
dropdown states
public string SelectedValue
{
get
{
return ddlStates.SelectedValue;
}
set
{
ddlStates.SelectedValue = value;
}
}
public string id
{
set
{
ddlStates.ID = value;
}
}
public string ValidationEnabled
{
set
{
rfvStates.Enabled = Convert.ToBoolean(value);
}
}
public string ValidationGroup
{
set
{
ddlStates.ValidationGroup = value;
rfvStates.ValidationGroup = value;
}
}
public string ValidationErrorMessage
{
set
{
rfvStates.ErrorMessage = value;
}
}
public string SelectedValue
{
get
{
return ddlStates.SelectedValue;
}
set
{
ddlStates.SelectedValue = value;
}
}
public short TabIndex
{
set
{
ddlStates.TabIndex = value;
}
}
Thursday, March 08, 2007
state abbreviations list (Dictionary)
Dictionary stateabbrs = new Dictionary();
stateabbrs.Add("Alabama","AL");
stateabbrs.Add("Alaska","AK");
stateabbrs.Add("Arizona","AZ");
stateabbrs.Add("Arkansas","AR");
stateabbrs.Add("California","CA");
stateabbrs.Add("Colorado","CO");
stateabbrs.Add("Connecticut","CT");
stateabbrs.Add("Delaware","DE");
stateabbrs.Add("Florida","FL");
stateabbrs.Add("Georgia","GA");
stateabbrs.Add("Hawaii","HI");
stateabbrs.Add("Idaho","ID");
stateabbrs.Add("Illinois","IL");
stateabbrs.Add("Indiana","IN");
stateabbrs.Add("Iowa","IA");
stateabbrs.Add("Kansas","KS");
stateabbrs.Add("Kentucky","KY");
stateabbrs.Add("Louisiana","LA");
stateabbrs.Add("Maine","ME");
stateabbrs.Add("Maryland","MD");
stateabbrs.Add("Massachusetts","MA");
stateabbrs.Add("Michigan","MI");
stateabbrs.Add("Minnesota","MN");
stateabbrs.Add("Mississippi","MS");
stateabbrs.Add("Missouri","MO");
stateabbrs.Add("Montana","MT");
stateabbrs.Add("Nebraska","NE");
stateabbrs.Add("Nevada","NV");
stateabbrs.Add("New Hampshire","NH");
stateabbrs.Add("New Jersey","NJ");
stateabbrs.Add("New Mexico","NM");
stateabbrs.Add("New York","NY");
stateabbrs.Add("North Carolina","NC");
stateabbrs.Add("North Dakota","ND");
stateabbrs.Add("Ohio","OH");
stateabbrs.Add("Oklahoma","OK");
stateabbrs.Add("Oregon","OR");
stateabbrs.Add("Pennsylvania","PA");
stateabbrs.Add("Rhode Island","RI");
stateabbrs.Add("South Carolina","SC");
stateabbrs.Add("South Dakota","SD");
stateabbrs.Add("Tennessee","TN");
stateabbrs.Add("Texas","TX");
stateabbrs.Add("Utah","UT");
stateabbrs.Add("Vermont","VT");
stateabbrs.Add("Virginia","VA");
stateabbrs.Add("Washington","WA");
stateabbrs.Add("West Virginia","WV");
stateabbrs.Add("Wisconsin","WI");
stateabbrs.Add("Wyoming","WY");
stateabbrs.Add("Alabama","AL");
stateabbrs.Add("Alaska","AK");
stateabbrs.Add("Arizona","AZ");
stateabbrs.Add("Arkansas","AR");
stateabbrs.Add("California","CA");
stateabbrs.Add("Colorado","CO");
stateabbrs.Add("Connecticut","CT");
stateabbrs.Add("Delaware","DE");
stateabbrs.Add("Florida","FL");
stateabbrs.Add("Georgia","GA");
stateabbrs.Add("Hawaii","HI");
stateabbrs.Add("Idaho","ID");
stateabbrs.Add("Illinois","IL");
stateabbrs.Add("Indiana","IN");
stateabbrs.Add("Iowa","IA");
stateabbrs.Add("Kansas","KS");
stateabbrs.Add("Kentucky","KY");
stateabbrs.Add("Louisiana","LA");
stateabbrs.Add("Maine","ME");
stateabbrs.Add("Maryland","MD");
stateabbrs.Add("Massachusetts","MA");
stateabbrs.Add("Michigan","MI");
stateabbrs.Add("Minnesota","MN");
stateabbrs.Add("Mississippi","MS");
stateabbrs.Add("Missouri","MO");
stateabbrs.Add("Montana","MT");
stateabbrs.Add("Nebraska","NE");
stateabbrs.Add("Nevada","NV");
stateabbrs.Add("New Hampshire","NH");
stateabbrs.Add("New Jersey","NJ");
stateabbrs.Add("New Mexico","NM");
stateabbrs.Add("New York","NY");
stateabbrs.Add("North Carolina","NC");
stateabbrs.Add("North Dakota","ND");
stateabbrs.Add("Ohio","OH");
stateabbrs.Add("Oklahoma","OK");
stateabbrs.Add("Oregon","OR");
stateabbrs.Add("Pennsylvania","PA");
stateabbrs.Add("Rhode Island","RI");
stateabbrs.Add("South Carolina","SC");
stateabbrs.Add("South Dakota","SD");
stateabbrs.Add("Tennessee","TN");
stateabbrs.Add("Texas","TX");
stateabbrs.Add("Utah","UT");
stateabbrs.Add("Vermont","VT");
stateabbrs.Add("Virginia","VA");
stateabbrs.Add("Washington","WA");
stateabbrs.Add("West Virginia","WV");
stateabbrs.Add("Wisconsin","WI");
stateabbrs.Add("Wyoming","WY");
Tuesday, July 18, 2006
Unable to add data connection. Key not valid for use in specified state. - MSDN Forums
solution:
1. Open the registry
2. Rename [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0]
To [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0back]
3. Restart Visual Studio
1. Open the registry
2. Rename [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0]
To [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0back]
3. Restart Visual Studio
Monday, October 24, 2005
Forcing File Downloads
In C# (ASP.NET) it’s just as simple:
private void Page_Load(object sender, System.EventArgs e)
{
// Disable caching this page (C#)
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Buffer = true;
Response.ContentType = "application/binary";
Response.AppendHeader("Content-Disposition: attachment; " +
filename=dlimg.png");
Response.WriteFile(Server.MapPath("images/dlimg.png");
Response.End();
}
private void Page_Load(object sender, System.EventArgs e)
{
// Disable caching this page (C#)
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Buffer = true;
Response.ContentType = "application/binary";
Response.AppendHeader("Content-Disposition: attachment; " +
filename=dlimg.png");
Response.WriteFile(Server.MapPath("images/dlimg.png");
Response.End();
}
Subscribe to:
Posts (Atom)