当前位置:编程学习 > C#/ASP.NET >>

数据库文件数据转存的问题,还有winform使用停表

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.Diagnostics;
using System.Data.Common;
using System.Data.SQLite;
using System.IO;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            System.Data.SQLite.SQLiteConnection.CreateFile("datasource");

            System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection();

            string datasource = "D:/Data.db";

            System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder();

            connstr.DataSource = datasource;

            conn.ConnectionString = connstr.ToString();

            conn.Open();

            System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();

            cmd.Connection = conn;

            Stopwatch watch = new Stopwatch();

            watch.Start();

            string sql = "SELECT * FROM test WHERE S LIKE '%100'";

            cmd.CommandText = sql;

            cmd.ExecuteNonQuery();

            System.Data.SQLite.SQLiteDataReader reader = cmd.ExecuteReader();

            watch.Stop();
            
            saveFileDialog1.Filter = "二进制文件(*.dat)|*.dat";

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
               
                FileStream myStream = new FileStream(saveFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                
                BinaryWriter myWriter = new BinaryWriter(myStream);
              
               myWriter.Write(reader.Read());             
                myWriter.Close();
              
                myStream.Close();

             }
       
        }
    }
}
是不是这句错了?select的结果无法存入二进制文件中。还有谁能把停表的显示在winForm中弄出来。再此谢过了
--------------------编程问答-------------------- myWriter.Write()
这里没有写对象的重载吧,你看看那个类的用法

http://msdn.microsoft.com/zh-cn/library/system.io.binarywriter.write(v=vs.80).aspx --------------------编程问答-------------------- reader.Read()返回的不是内容,你看看帮助,用索引访问内容reader[0], reader[1]
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,