"编号" "日期" "时间" "考勤机号"
"00000" "03-11-14" "00:00:00" "1"
"00002" "03-11-14" "10:29:34" "1"
"00002" "03-11-14" "10:33:02" "1"
"00157" "03-11-14" "10:34:24" "1"
"00157" "03-11-14" "10:34:44" "1"
"00157" "03-11-14" "10:35:31" "1"
"00157" "03-11-14" "10:37:31" "1"
"00002" "03-11-14" "10:48:31" "1"
"00157" "03-11-14" "12:16:04" "1"
"00157" "03-11-14" "12:17:19" "1"
"00157" "03-11-14" "12:17:51" "1"
"00002" "03-11-14" "10:18:09" "1"
"00002" "03-11-14" "10:30:53" "1"
"00157" "03-11-14" "10:34:22" "1"
"00157" "03-11-14" "10:34:26" "1"
"00157" "03-11-14" "10:35:12" "1"
"00157" "03-11-14" "10:35:54" "1"
"00157" "03-11-14" "10:38:27" "1"
"00002" "03-11-14" "12:05:31" "1"
"00157" "03-11-14" "12:17:06" "1"
"00157" "03-11-14" "12:17:36" "1"
看看这段代码就可以了,类似 private System.IO.StreamReader GetStreamReader()
{
HttpPostedFile hpf = fileData.PostedFile;
System.IO.Stream stream = hpf.InputStream;
System.IO.StreamReader sr = new System.IO.StreamReader(stream);
return sr;
} private void LoadCardRecord()
{
string strText = "";
string strCurLine = "";
int rows = 0;
System.IO.StreamReader sr = GetStreamReader(); strCurLine = sr.ReadLine();
txtFileContent.Value = "";
while(strCurLine != null && strCurLine != "")
{
strText += strCurLine;
txtFileContent.Value += strCurLine + "\n";
strCurLine = sr.ReadLine();
rows++;
}
txtFileContent.Rows = rows;
sr.Close();
} private void Save()
{
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
try
{
WebMIS.Web.Service.Web w = new WebMIS.Web.Service.Web();
conn.ConnectionString = w.ConnectionString;
conn.Open();
}
catch
{
Response.Write("<script>alert('打开数据库失败!');</script>");
return;
}
System.IO.StreamReader sr = GetStreamReader();
bool blnHasData = false; if (sr != null)
{
string strCurLine = ""; //当前行记录文本
string strSQL = ""; //保存当前记录的SQL
string[] arrCurLine; //当前行记录以Tab键分隔的文本数组
int count = 0; /*
"编号" "日期" "时间" "考勤机号"
"00000" "03-11-14" "00:00:00" "1"
"00002" "03-11-14" "10:29:34" "1"
"00002" "03-11-14" "10:33:02" "1"
*/
strCurLine = sr.ReadLine(); //第一行为标题 strCurLine = sr.ReadLine(); //第二行开始为考勤数据
if (strCurLine != null)
{
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = conn; while(strCurLine != null && strCurLine != "")
{
try
{
arrCurLine = strCurLine.Split('\t');
strSQL = "Insert Into CardRecord(ID,行值,编号,日期,时间,考勤机号";
strSQL += ") Values (";
strSQL += "'" + System.Guid.NewGuid(); //ID
strSQL += "','" + strCurLine; //行值,把整个写到一个字段
strSQL += "','" + arrCurLine[0].Substring(1,arrCurLine[0].Length-2);
strSQL += "','" + arrCurLine[1].Substring(1,arrCurLine[1].Length-2);
strSQL += "','" + arrCurLine[2].Substring(1,arrCurLine[2].Length-2);
strSQL += "','" + arrCurLine[3].Substring(1,arrCurLine[3].Length-2);
strSQL += "')";
/*
纪录结构:
0: 卡类型
1、2: 卡流水号,1为低位元,2为高位
3 – 8: 打卡日期、时间,格式为“YYMMDDHHMNSS”
9: 进出标志,0为无标志,1为进,2为出。
*/ //写数据库
cmd.CommandText = strSQL;
cmd.ExecuteNonQuery();
count++; //执行成功,计数器加1
}
catch(Exception e)
{
//throw new Exception(e.Message);
} //读下一行
strCurLine = sr.ReadLine(); }
conn.Close();
conn.Dispose();
sr.Close();
blnHasData = true;
Response.Write("<script>alert('成功保存了" + count + "条记录!');</script>"); }
}
if(!blnHasData)
{
Response.Write("<script>alert('没有读取数据!');</script>");
}
}
"00000" "03-11-14" "00:00:00" "1"
"00002" "03-11-14" "10:29:34" "1"
"00002" "03-11-14" "10:33:02" "1"
"00157" "03-11-14" "10:34:24" "1"
"00157" "03-11-14" "10:34:44" "1"
"00157" "03-11-14" "10:35:31" "1"
"00157" "03-11-14" "10:37:31" "1"
"00002" "03-11-14" "10:48:31" "1"
"00157" "03-11-14" "12:16:04" "1"
"00157" "03-11-14" "12:17:19" "1"
"00157" "03-11-14" "12:17:51" "1"
"00002" "03-11-14" "10:18:09" "1"
"00002" "03-11-14" "10:30:53" "1"
"00157" "03-11-14" "10:34:22" "1"
"00157" "03-11-14" "10:34:26" "1"
"00157" "03-11-14" "10:35:12" "1"
"00157" "03-11-14" "10:35:54" "1"
"00157" "03-11-14" "10:38:27" "1"
"00002" "03-11-14" "12:05:31" "1"
"00157" "03-11-14" "12:17:06" "1"
"00157" "03-11-14" "12:17:36" "1"
看看这段代码就可以了,类似 private System.IO.StreamReader GetStreamReader()
{
HttpPostedFile hpf = fileData.PostedFile;
System.IO.Stream stream = hpf.InputStream;
System.IO.StreamReader sr = new System.IO.StreamReader(stream);
return sr;
} private void LoadCardRecord()
{
string strText = "";
string strCurLine = "";
int rows = 0;
System.IO.StreamReader sr = GetStreamReader(); strCurLine = sr.ReadLine();
txtFileContent.Value = "";
while(strCurLine != null && strCurLine != "")
{
strText += strCurLine;
txtFileContent.Value += strCurLine + "\n";
strCurLine = sr.ReadLine();
rows++;
}
txtFileContent.Rows = rows;
sr.Close();
} private void Save()
{
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
try
{
WebMIS.Web.Service.Web w = new WebMIS.Web.Service.Web();
conn.ConnectionString = w.ConnectionString;
conn.Open();
}
catch
{
Response.Write("<script>alert('打开数据库失败!');</script>");
return;
}
System.IO.StreamReader sr = GetStreamReader();
bool blnHasData = false; if (sr != null)
{
string strCurLine = ""; //当前行记录文本
string strSQL = ""; //保存当前记录的SQL
string[] arrCurLine; //当前行记录以Tab键分隔的文本数组
int count = 0; /*
"编号" "日期" "时间" "考勤机号"
"00000" "03-11-14" "00:00:00" "1"
"00002" "03-11-14" "10:29:34" "1"
"00002" "03-11-14" "10:33:02" "1"
*/
strCurLine = sr.ReadLine(); //第一行为标题 strCurLine = sr.ReadLine(); //第二行开始为考勤数据
if (strCurLine != null)
{
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = conn; while(strCurLine != null && strCurLine != "")
{
try
{
arrCurLine = strCurLine.Split('\t');
strSQL = "Insert Into CardRecord(ID,行值,编号,日期,时间,考勤机号";
strSQL += ") Values (";
strSQL += "'" + System.Guid.NewGuid(); //ID
strSQL += "','" + strCurLine; //行值,把整个写到一个字段
strSQL += "','" + arrCurLine[0].Substring(1,arrCurLine[0].Length-2);
strSQL += "','" + arrCurLine[1].Substring(1,arrCurLine[1].Length-2);
strSQL += "','" + arrCurLine[2].Substring(1,arrCurLine[2].Length-2);
strSQL += "','" + arrCurLine[3].Substring(1,arrCurLine[3].Length-2);
strSQL += "')";
/*
纪录结构:
0: 卡类型
1、2: 卡流水号,1为低位元,2为高位
3 – 8: 打卡日期、时间,格式为“YYMMDDHHMNSS”
9: 进出标志,0为无标志,1为进,2为出。
*/ //写数据库
cmd.CommandText = strSQL;
cmd.ExecuteNonQuery();
count++; //执行成功,计数器加1
}
catch(Exception e)
{
//throw new Exception(e.Message);
} //读下一行
strCurLine = sr.ReadLine(); }
conn.Close();
conn.Dispose();
sr.Close();
blnHasData = true;
Response.Write("<script>alert('成功保存了" + count + "条记录!');</script>"); }
}
if(!blnHasData)
{
Response.Write("<script>alert('没有读取数据!');</script>");
}
}
解决方案 »
- C# winform程序连接sql数据库,必须要在客户机上安装sql服务器吗?那个本地数据库怎么用?
- C#调用c++写的dll的问题
- C# 引用类有几种方法
- OpenRead与OpenReadAsync的区别
- treeview控件。请大家重头到尾给列举列举。
- .Net里面有没有类似Java的HtmlParser开源项目??还恳请大家指点迷津!!
- 利用c#调用存储过程出现timeout exceeded的问题
- 间隔一定事件后,系统自动更新某些状态信息的问题。比如图书管理系统中借书30天后到期的问题。
- c++里的wchar_t *转c#?
- 哪里有DUWAMISH7.0下载
- 关于CLONE,请问下面2段CODE有什么不 同?
- 有关WinForm下DataGrid用法的问题,就这些分了,各位帮忙给个思路
DataRow mydr;string strpath = "";
string strline;
string [] aryline;mydc = new DataColumn("name");
mydt.Columns.Add(mydc);mydc = new DataColumn("tel1");
mydt.Columns.Add(mydc);mydc = new DataColumn("tel2");
mydt.Columns.Add(mydc);mydc = new DataColumn("mail");
mydt.Columns.Add(mydc);System.IO.StreamReader mysr = new System.IO.StreamReader(strpath);strline = mysr.ReadLine();
while(strline != null && strline.Length > 0)
{
aryline = strline.Split(new char[]{','});
mydr = mydt.NewRow();
mydr[0] = aryline[0];
mydr[1] = aryline[1];
mydr[2] = aryline[2];
mydr[3] = aryline[3]; mydt.Rows.Add(mydr);
strline = mysr.ReadLine();
}
你using了哪些?
txtFileContent从何而来?
bool blnFlag = true;
DataTable mydt = new DataTable("myTableName");DataColumn mydc;
DataRow mydr;string strpath = "";
string strline;
string [] aryline; System.IO.StreamReader mysr = new System.IO.StreamReader(strpath);strline = mysr.ReadLine();
while(strline != null && strline.Length > 0)
{
aryline = strline.Split(new char[]{'|'}); if (blnFlag)
{
blnFlag = false;
intColCount = aryline.Length;
for (int i = 0; i < aryline.Length; i++)
{
mydc = new DataColumn(aryline[i]);
mydt.Columns.Add(mydc);
}
} mydr = mydt.NewRow();
for (int i = 0; i < intColCount; i++)
{
mydr[i] = aryline[i];
mydt.Rows.Add(mydr);
}
strline = mysr.ReadLine();
}
for (int i = 0; i < intColCount; i++)
{
mydr[i] = aryline[i];
mydt.Rows.Add(mydr);
}
运行,循环到i=1,插入mydt的时候,报该行已经属于此表。
bool blnFlag = true;
DataTable mydt = new DataTable("myTableName");DataColumn mydc;
DataRow mydr;string strpath = "";
string strline;
string [] aryline; System.IO.StreamReader mysr = new System.IO.StreamReader(strpath);while((strline = mysr.ReadLine()) != null)
{
aryline = strline.Split(new char[]{'|'}); if (blnFlag)
{
blnFlag = false;
intColCount = aryline.Length;
for (int i = 0; i < aryline.Length; i++)
{
mydc = new DataColumn(aryline[i]);
mydt.Columns.Add(mydc);
}
} mydr = mydt.NewRow();
for (int i = 0; i < intColCount; i++)
{
mydr[i] = aryline[i];
}
mydt.Rows.Add(mydr);
}