winform的读取有一定规律的文档生成sql语句
想了想干脆打包个能够分割字符串的winform程序来生成insert into,在某种程度上实现自由点的sql语句,比如可以自己输入表名,字段,但是字段数目是要确定的,O(∩_∩)O~,这点还没实现自由,但对我来说还够用,谁如果想到好的方法实现字段也可以自动的话,请告诉我啊Q:598214382
上代码:
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; namespace Split { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void buttonRead_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (DialogResult.OK == ofd.ShowDialog()) { string fileName = ofd.FileName; textBoxFile.Text = fileName; labelPath.Text = fileName; } } private void buttonBirth_Click(object sender, EventArgs e) { birthsql(gettext(labelPath.Text)); } /// <summary> /// 读取txt文件的内容 /// </summary> /// <returns>以字符串类型返回</returns> protected string gettext(string FilePath) { //StreamReader objStreamReader = File.OpenText(FilePath); FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read); StreamReader objStreamReader = new StreamReader(fs, Encoding.Default); string contents = objStreamReader.ReadToEnd(); fs.Close(); return contents; } /// <summary> /// 生成sql语句 /// </summary> /// <returns>返回标准sql语句</returns> protected void birthsql(string str) { string[] strarr = str.Split(Convert.ToChar(textBoxSplit.Text.Trim())); int j = 0; using (StreamWriter sw = new StreamWriter(@"D:\birth.sql")) { foreach (string i in strarr) { string strsql = "insert into " + textBoxTableName.Text + "(" + textBoxField.Text + ") values('A" + j.ToString() + ",'" + i.ToString() + "');"; sw.WriteLine(strsql); j++; } } } } }
前台截个图
其实就是个一般的工具,目前来说够我用了,呵呵
上code:demo下载
-------------------------------------------------
保持专注,只做一件事,做好这件事!@
-------------------------------------------------