using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.IO;
namespace writingCSV
{
class Program
{
static async Task Main(string[] args)
{
var PatientEmails = await GetPatients();
Type myType = PatientEmails.GetType();
Console.WriteLine(myType);
}
public class PatientSurvey: IDisposable
{
public string Location { get; set; }
public string Email { get; set; }
public void Dispose()
{
throw new NotImplementedException();
}
}
static public async Task<IEnumerable<PatientSurvey>> GetPatients()
{
var connectionString = "SERVER INFORMATION";
using (var cnn = new SqlConnection(connectionString))
{
cnn.Open();
var patientSurveys = await cnn.QueryAsync<PatientSurvey>("STORED PROC NAME",
null,
commandTimeout: 120,
commandType: CommandType.StoredProcedure);
return patientSurveys;
}
}
}
}
我正在嘗試將資料從資料庫寫入 CSV 檔案。我已成功連接到資料庫并將資料提取到 C# 物件中,但我無法弄清楚如何修改我的資料,因此我實際上可以將其寫入檔案中。該PatientEmails變數中包含資料,但它似乎只是PatientSurvey該類的一個實體。
如果我通過回圈運行我的變數,它會在每次foreach回圈時列印出來。writingCSV.Program.PatientSurvey
uj5u.com熱心網友回復:
我看不出有什么問題。GetPatients回傳一個IEnumerableof PatientSurveyso 確實在串列上回圈列印出來writingCSV.Program.PatientSurvey。你會期待什么?如果您的目標是列印患者的電子郵件,那么您應該寫類似
foreach (var p in patientEmails) {
Console.WriteLine(p.Email);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/464403.html
