[在将文本数据插入SQL数据库表之前如何检查文本文件中是否存在特定数据?

问题描述 投票:0回答:1

我有一个员工文本文件employee.txt,其中包含一些数据。

例如:

empID, FirstName, LastNme

我想读取文件并从中获取empId,并将其传递给函数以检查SQL数据库表中是否已存在empId

这是我的职能:

public bool DoesEmployeeExist(int empId)
{
    bool ret;

    try
    {
        string sql = "Select empId from Employees where empId = '" + empId + "'";

        Object obj = _idac.GetSingleAnswer(sql);

        if (obj != null)
        {
            ret = true;
        }
        else
        {
            ret = false;
        }
    }
    catch (Exception)
    {
        throw;
    }

    return ret;
}

如何从文件中获取empId

如果没有emptId,如何在SQL数据库表中插入文件?

我应该将employee.txt文件作为字符串传递给类似的函数,然后使用批量插入在数据库中添加数据:

public void InsertOrUpdateEmployee(string employees)
{
    string sql = "BULK INSERT Employee FROM '" + employees + "'" +
                 " WITH(FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')";
}

或作为]传递>

List<Employees> employee = new <Employees>();

我有一个雇员文本文件employee.txt,其中包含一些数据。例如:empID,FirstName,LastNme我想读取文件并从中获取empId,并将其传递给函数以检查...

c# sql database visual-studio 3-tier
1个回答
0
投票

根据您的问题,如果

© www.soinside.com 2019 - 2024. All rights reserved.