Miscellaneous Code – DotNet

Add Values in ComboBox in C#:

cmbCustomerName.Items.Add("Akanksha");

Get the selected item value from combo Box:

string customerName = cmbCustomerName.GetItemText(cmbCustomerName.SelectedItem);

Show current Date and Time:

lbldate.Text=DateTime.Now.ToString();

Connection String to connect Visual Studio C# Windows Form Application to MS Access .accdb Database:

string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\DailyExpenses.accdb";

Check for zero rows in a DataTable:

if(dataTable==null){......}

Fetch DataTable CellValue into a variable:

txtCustomerID.Text = custDt.Rows[0]["CustomerID"].ToString();

Enter only numbers and Backspace in TextBox:

private void txtCustomerPhone_KeyPress(object sender, KeyPressEventArgs e)
{
     e.Handled = !(char.IsDigit(e.KeyChar) || e.KeyChar == 8);
}
Unknown's avatar

Author: Akanksha Gupta

I am a developer and working on SharePoint and Project Server in an MNC. I have more than 10 years of experience in the same field.

Leave a comment

Power Platform Academy

Start or Upgrade your Career with Power Platform

Learn with Akanksha

Python | Azure | AI/ML | OpenAI | MLOps

Design a site like this with WordPress.com
Get started