我有一些考勤设备的文本文件。该文件如下所示:
010:0007739166:20120908:071009:BLANK !!:11
010:0013646521:20120908:073125:BLANK !!:11
010:0010840695:20120908:073129:BLANK !!:11
010:0005546931:20120908:073131:BLANK !!:11
010:0013656129:20120908:073136:BLANK !!:11
010:0010827749:20120908:073222:BLANK !!:11
010:0009668536:20120908:073251:BLANK !!:11
010:0009673161:20120908:073410:BLANK !!:11
我需要使用 c# 应用程序将它们插入到我的 SQL Server 数据库中。我正在使用的代码是:
string[] alllines = File.ReadAllLines(txtFilePath.Text);
for (int i = 1; i < alllines.Length; i++)
{
OdbcConnection conn = new OdbcConnection(connstring);
conn.Open();
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = conn;
string[] items = alllines[i].Split(new char[] { ":" });
string cardno = items[1];
string date = items[2];
string time = items[3];
string datetime = date + " " + time;
cmd.CommandText = "insert into tbl_card values('" + cardno + "','" + date + "','" + DateTime.Parse(datetime) + "','Entry','" + System.DateTime.Now.ToString() + "')";
cmd.CommandType = CommandType.Text;
OdbcDataReader dr = cmd.ExecuteReader();
conn.Dispose();
}
我得到的错误是:
无法将类型“字符串”隐式转换为“字符”