将记事本中的数据导入数据库(winform)
来源:互联网 发布:sent it 编辑:程序博客网 时间:2024/05/04 02:06
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
namespace 将记事本中的数据导入数据库_winform_
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//导出文本文件中的内容
StreamReader sr = new StreamReader(new FileStream(@"G:\1.txt", FileMode.Open, FileAccess.Read), System.Text.Encoding.Default);
string sLine = "";
ArrayList al = new ArrayList();
//foreach (string sOutput in al)
// MessageBox.Show(sOutput);
//连接数据库
string connstr = ConfigurationManager.ConnectionStrings["strcon"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
while (sLine != null)
{
sLine = sr.ReadLine();
if (sLine != null)
al.Add(sLine);
}
sr.Close();
foreach (string sOutput in al)
{
string[] strs = sOutput.Split('|');
string name ="'"+ strs[0]+"'";
string phone = strs[1];
string address = "'" + strs[2] + "'";
string age = strs[3];
string sex = "'" + strs[4] + "'";
cmd.CommandText = "insert into T_StudentsInfo(name,phone,address,age,sex)values("+name+","+phone+","+address+","+age+","+sex+")";
//cmd.Parameters.AddWithValue("@username", name);
//cmd.Parameters.AddWithValue("@phone", Convert.ToInt32(phone));
//cmd.Parameters.AddWithValue("@address", address);
//cmd.Parameters.AddWithValue("@age", Convert.ToInt32(age));
//cmd.Parameters.AddWithValue("@sex", sex);
cmd.ExecuteNonQuery();
}
}
}
MessageBox.Show("导成功了");
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
namespace 将记事本中的数据导入数据库_winform_
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//导出文本文件中的内容
StreamReader sr = new StreamReader(new FileStream(@"G:\1.txt", FileMode.Open, FileAccess.Read), System.Text.Encoding.Default);
string sLine = "";
ArrayList al = new ArrayList();
//foreach (string sOutput in al)
// MessageBox.Show(sOutput);
//连接数据库
string connstr = ConfigurationManager.ConnectionStrings["strcon"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
while (sLine != null)
{
sLine = sr.ReadLine();
if (sLine != null)
al.Add(sLine);
}
sr.Close();
foreach (string sOutput in al)
{
string[] strs = sOutput.Split('|');
string name ="'"+ strs[0]+"'";
string phone = strs[1];
string address = "'" + strs[2] + "'";
string age = strs[3];
string sex = "'" + strs[4] + "'";
cmd.CommandText = "insert into T_StudentsInfo(name,phone,address,age,sex)values("+name+","+phone+","+address+","+age+","+sex+")";
//cmd.Parameters.AddWithValue("@username", name);
//cmd.Parameters.AddWithValue("@phone", Convert.ToInt32(phone));
//cmd.Parameters.AddWithValue("@address", address);
//cmd.Parameters.AddWithValue("@age", Convert.ToInt32(age));
//cmd.Parameters.AddWithValue("@sex", sex);
cmd.ExecuteNonQuery();
}
}
}
MessageBox.Show("导成功了");
}
}
}
- 将记事本中的数据导入数据库(winform)
- c#将datagridview中的数据导入到Excel中(winForm)
- C#Winform 将DataGridView中的数据导入到Excel中
- 如何将Excel中的数据导入数据库
- java将excel数据导入数据库,将数据库中的数据导入excel
- 将其他数据库中的数据导入access数据库
- 怎样将Excel中的数据导入到SQLServer2000数据库中
- 怎样将Excel中的数据导入到SQLServer2000数据库中
- 将Excel或者Txt文件中的数据导入Oracle数据库
- 将Excel文件中的数据导入SQL数据库中
- 将DataTable中的数据导入到数据库中
- 使用sqoop将MySQL数据库中的数据导入Hbase
- 使用sqoop将MySQL数据库中的数据导入Hbase (转)
- .net实现将Excel中的数据导入数据库
- 如何将Excel表中的数据导入到数据库
- 如何将Excel表中的数据导入到数据库
- 将excel文件中的数据导入导出至SQL数据库
- 怎样将excel中的数据导入到oracle数据库中
- PHP简单工厂模式(simple factory)趣味讲解
- sybase iq选择topN数据
- hadoop 配置项的调优
- LabVIEW中对控件的属性"disable"的控制
- hadoop参数配置(mapreduce数据流)
- 将记事本中的数据导入数据库(winform)
- vim 命令(全)
- 设计模式——装饰设计模式
- hadoop作业调优参数整理及原理
- 二、闪烁灯、流水灯
- PowerManagerService framework层的分析
- Basic OCR in OpenCV
- jvm规范规定的对类(或者接口)初始化的情况
- 做原创文章的十大ideas