我有一个员工文本文件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,并将其传递给函数以检查...
根据您的问题,如果