You will also need to have MDAC
(Microsoft Data Access Components).
In order to help you with the connection string and its parameters for a data file such as an Access database, please follow the following link specific to Access: Access
.
For other connection strings in general: ConnectionStrings.com
.
In short, you need to specify your complet filename to the Access database file in your connectionString.
using (OleDBConnection connection = new OleDBConnection(connectiongString)) {
if (connection.State != ConnectionState.Open)
connection.Open();
string sql = "INSERT INTO Student (Id, Name) VALUES (@idParameter, @nameParameter)"
using (OleDBCommand command = connection.CreateCommand()) {
command.CommandText = sql;
command.CommandType = CommandType.Text;
OleDBParameter idParameter = command.CreateParameter()
idParameter.DbType = System.Int32;
idParameter.Direction = Parameterdirection.Input;
idParameter.Name = "@idParameter";
idParameter.Value = studentId; // Where studentId is an int variable that holds your parsed TextBox.Text property value.
OleDBParameter nameParameter = command.CreateParameter()
// Do the same as you did above for the nameParameter.
try {
command.ExecuteNonQuery()
} finally {
command.Dispose();
connection.Dispose();
}
}
}
Disclaimer This code is provided as-is as it was not compiled nor tested. That is only to show you the idea of how it works. Further tests might be necessary depending on your project architecture or else.