Protected Function GetDataTableFromAccessDatabase(ConnectionString As String, SelectString As String) As Data.DataTable Dim QueryResultsDataTable As New Data.DataTable 'To get the connection string: Server Explorer... Data Connections... Select an Access database... Press F4... Copy connection string to the clipboard. Dim DataConnection As New OleDb.OleDbConnection DataConnection.ConnectionString = ConnectionString Dim OleCommand As New OleDb.OleDbCommand(SelectString, DataConnection) Dim DataAdapter As New OleDb.OleDbDataAdapter(OleCommand) DataAdapter.Fill(QueryResultsDataTable) Return QueryResultsDataTable End Function
Awes C# Tips & Tricks
Get table from Access database
Detect When Network Goes Up or Down
namespace My
{
internal partial class MyApplication
{
private void MyApplication_NetworkAvailabilityChanged(object sender, Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs e)
{
if (e.IsNetworkAvailable) {
Diagnostics.Debug.WriteLine("Network went up.");
} else {
Diagnostics.Debug.WriteLine("Network went down.");
}
}
public MyApplication()
{
NetworkAvailabilityChanged += MyApplication_NetworkAvailabilityChanged;
}
}
}
Difference Between Dates/Times Including Daylight Savings Time
System.DateTime StartTime = DateTime.SpecifyKind(3/8/2009 1:59:00 AM, DateTimeKind.Local);
System.DateTime EndTime = DateTime.SpecifyKind(3/8/2009 3:01:00 AM, DateTimeKind.Local);
TimeSpan TimeDifference = EndTime.ToUniversalTime - StartTime.ToUniversalTime;
ulong MinutesBetweenTimes = DateDiff(DateInterval.Minute, StartTime.ToUniversalTime, EndTime.ToUniversalTime);
Force the program to pause
[] Paws = new[];
public void Paws(ulong Milliseconds)
{
System.DateTime WaitUntil = Now + new TimeSpan(0, 0, 0, 0, Milliseconds);
while (Now < WaitUntil) {
Threading.Thread.Sleep(18);
Application.DoEvents();
}
}
Alphabetize drop down list and remove duplicate items.
protected void AlphabetizeDropDownListAndRemoveDuplicates(DropDownList ThisDropDownList)
{
SortedList AlphabetizedItems = new SortedList();
foreach (ListItem ThisListItem in ThisDropDownList.Items) {
if (AlphabetizedItems.Contains(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Strings.Trim(ThisListItem.Text))) == false) {
AlphabetizedItems.Add(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Strings.Trim(ThisListItem.Text)), ThisListItem.Value);
}
}
ThisDropDownList.Items.Clear();
foreach (DictionaryEntry AlphabetizedItem in AlphabetizedItems) {
ThisDropDownList.Items.Add(new ListItem(AlphabetizedItem.Key, AlphabetizedItem.Value));
}
}
Create a table of unique cells from a column in a table.
Data.DataTable UniqueTable = DataTable1.DefaultView.ToTable(true, new string[] { "FieldName" });
Display row numbers in a DataGridView
{
if (DataGridView1.Rows.Count > 0) {
for (ulong r = 0; r <= DataGridView1.Rows.Count - 1; r++) {
DataGridView1.Rows(r).HeaderCell.Value = (r + 1).ToString;
}
}
DataGridView1.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
}
Subscribe to:
Posts (Atom)