Hello,
I would like to create a function and return a single value like an example;
public static string GetValueFromAccess(string uniqueID) {....}
As in example i'd like to get result "DF556-33446" when i set uniquID = 30075
I'm trying to edit this code to implement it but didn't succeeded.
private void AccessReader_Click(object sender, RoutedEventArgs e)
{
string connetionString = null;
OleDbConnection cnn;
OleDbCommand cmd;
string sql = null;
connetionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Mode=Read;Data Source=E:\SampleData\ASampleDatabase.accdb";
sql = "Select Count(*) from [Asset Items]";
cnn = new OleDbConnection(connetionString);
try
{
cnn.Open();
MessageBox.Show("Connection Opened ");
cmd = new OleDbCommand(sql, cnn);
cmd.ExecuteNonQuery();
cmd.Dispose();
cnn.Close();
MessageBox.Show(" ExecuteNonQuery in OleDbConnection executed !! :");
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! " + ex.ToString());
}
}
Open in new window
You can find sample database on attachment also.
ASampleDatabase.accdb
Open in new window