Are you saying, without actually saying, that you don't know how to get the data from the database in the first place? If so then it's important to give us that information because we are unlikely to guess. If not then it's pretty much irrelevant because where the data comes from doesn't really affect how you use it. Writing to a StreamWriter is the same no matter where the data comes from. As such, any example that you have already found when searching the web is applicable.