private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.InitialDirectory = @"c:\";
openFileDialog1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"; if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
int n = 0;
string fname = openFileDialog1.FileName;
StreamReader sr = new StreamReader(@fname, System.Text.Encoding.GetEncoding("gb2312"));
char[] parsChar = { ' ' };
string water = string.Empty;
string date1 = string.Empty;
string time1 = string.Empty;
string temp = string.Empty;
string date2 = string.Empty;
string time2 = string.Empty;
string space = string.Empty;
string sctemp = textBox1.Text;
string tmpLine;
string splitline;
string[] line; //string[] line2;
while ((tmpLine = sr.ReadLine()) != null)
{
n++;
linebuilder.Append(tmpLine + " ");
if (n % 2 == 0)
{
splitline = linebuilder.ToString();
line = splitline.Split(parsChar);
water = line[0];
date1 = line[1];
time1 = line[2];
space = line[3];
temp = line[4];
date2 = line[5];
time2 = line[6];
OleDbCommand cmd = new OleDbCommand("Insert Into txttest ([water],[date1],[time1],[temp],[date2],[time2],[sctemp]) values ('" + water + "','" + date1 + "','" + time1 + "','" + temp + "','" + date2 + "','" + time2 + "','" + sctemp + "') ");
using (OleDbConnection conn = new OleDbConnection(connStr))
{
cmd.CommandType = CommandType.Text;
if (conn.State != ConnectionState.Open)
{ conn.Open(); }
cmd.Connection = conn;
cmd.ExecuteNonQuery();
} } }
}
}编译时也没有错误。但调试的时候会卡住。用了debug版本运行后出现上图中的错误。
串口通信 access
{
openFileDialog1.InitialDirectory = @"c:\";
openFileDialog1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"; if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
int n = 0;
string fname = openFileDialog1.FileName;
StreamReader sr = new StreamReader(@fname, System.Text.Encoding.GetEncoding("gb2312"));
char[] parsChar = { ' ' };
string water = string.Empty;
string date1 = string.Empty;
string time1 = string.Empty;
string temp = string.Empty;
string date2 = string.Empty;
string time2 = string.Empty;
string space = string.Empty;
string sctemp = textBox1.Text;
string tmpLine;
string splitline;
string[] line; //string[] line2;
while ((tmpLine = sr.ReadLine()) != null)
{
n++;
linebuilder.Append(tmpLine + " ");
if (n % 2 == 0)
{
splitline = linebuilder.ToString();
line = splitline.Split(parsChar);
water = line[0];
date1 = line[1];
time1 = line[2];
space = line[3];
temp = line[4];
date2 = line[5];
time2 = line[6];
OleDbCommand cmd = new OleDbCommand("Insert Into txttest ([water],[date1],[time1],[temp],[date2],[time2],[sctemp]) values ('" + water + "','" + date1 + "','" + time1 + "','" + temp + "','" + date2 + "','" + time2 + "','" + sctemp + "') ");
using (OleDbConnection conn = new OleDbConnection(connStr))
{
cmd.CommandType = CommandType.Text;
if (conn.State != ConnectionState.Open)
{ conn.Open(); }
cmd.Connection = conn;
cmd.ExecuteNonQuery();
} } }
}
}编译时也没有错误。但调试的时候会卡住。用了debug版本运行后出现上图中的错误。
串口通信 access
解决方案 »
- 如何把DataGridView的数据导进Excel中?
- 讨论下:SQL语句写在程序里面还是用存储过程好?
- GET方式,i如何利用httpwebresponse获取新浪页面的cookie
- 急!怎么加解密app.config配置?
- 请高手回答一个怪异的问题,在xp+sp2中安装.net运行库不成功.谢谢
- 如何把DropDownList控件的三D效果去掉(边框改成一条线型)?
- 一个自己写的公用函数,很多地方调用,出错的时候不知是哪一个调用出错,该怎么捕捉错误呢?
- 赠送网做好了怎么宣传最有效?
- 如何在windows application中弹出信息对话框
- 急!帮我一下吧,关于VS.NET换NAmespace名称的问题
- 异步10秒后再做另一件事,UI受阻
- c# 如何利用经纬度数据 在平面上画图
2,LZ你的split代码好奇怪, 从N=3开始你怎么进入ACCESS表?