Category Archives: database

Use a TextFieldParser to read fixed-width data in C#

This example uses a TextFieldParser object to load fixed-width data from a file that contains names and addresses. Each field has a fixed width. Some records also have ZIP+4 format ZIP codes (for example, 08109-2120) and the program should discard … Continue reading

Posted in classes, database, files, parsing | Tagged , , , , , , , , , , , , , , , | Leave a comment

Use a TextFieldParser to read delimited data in C#

This example uses a TextFieldParser object to parse a data file that contains name and address data. The data contains fields delimited by commas and semi-colons. Some records also have ZIP+4 format ZIP codes (for example, 08109-2120) and the program … Continue reading

Posted in classes, database, files, parsing | Tagged , , , , , , , , , , , , , | 2 Comments

Link ComboBox and ListBox data sources in C#

Few people know that you can link ComboBox and ListBox controls to data sources. If you set their DataSource property to an array or other object holding values, the control will display those values. This can be a convenient way … Continue reading

Posted in arrays, controls, database | Tagged , , , , , , , , , , , | Leave a comment

Reset an Access autonumber field in C#

The post Get an autonumber value that was just inserted in C# explains how to use autonumbered fields. This post explains how you can reset the value used by an autonumber field. To reset an autonumber field in an Access … Continue reading

Posted in ADO.NET, database | Tagged , , , , , , , , , , , , | Leave a comment

Get an autonumber value that was just inserted in C#

If a database field is an autonumber field, then the database automatically generates values for it. For example, suppose a Students tables has typical fields such as FirstName, LastName, EnrollmentYear, and so forth. You could make the StudentId field be … Continue reading

Posted in ADO.NET, database | Tagged , , , , , , , , , , , | 1 Comment

Use SQL queries to display master-detail data in C#

This example uses SQL queries to load master-detail data only when it is needed. For quite a while now, the .NET-ish way to manipulate data from a database has been to load it into a DataSet stored in memory and … Continue reading

Posted in ADO.NET, controls, database | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , | 4 Comments

Generate random data in an Access database in C#

This example shows how you can generate random data for students and their test scores in an Access database. I often build examples that manipulate databases. Those examples are more interesting if the database holds lots of data, but it’s … Continue reading

Posted in ADO.NET, algorithms, database | Tagged , , , , , , , , , , , , , , | Leave a comment

Display master-detail data in a DataGrid in C#

At design time, I added the example’s Contacts.mdb database to the project, set its “Build Action” property to Content, and set its “Copy to Output Directory” property to “Copy if newer.” That way the database is copied into the executable … Continue reading

Posted in ADO.NET, controls, database | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , | 1 Comment

Let the user pick database search criteria in C#

The top part of this program holds three columns of controls. The left column contains combo boxes holding the names of the fields in a database table. The middle column holds operators such as =, <, and >=. The right … Continue reading

Posted in database, user interface | Tagged , , , , , , , , , , , | 1 Comment

Save images in an Access database in WPF and C#

The example Display images in an Access database in WPF and C# shows how you can display images saved in an Access database. Of course that begs the question, “How do you save images in the database in the first … Continue reading

Posted in database, graphics, image processing, Office | Tagged , , , , , , , , , , , , , , , | Leave a comment