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

bs897945043 2012-04-06 09:39:11
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中弄出来。再此谢过了
...全文
55 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bdmh 2012-04-07
  • 打赏
  • 举报
回复
reader.Read()返回的不是内容,你看看帮助,用索引访问内容reader[0], reader[1]
mingcsharp 2012-04-07
  • 打赏
  • 举报
回复
myWriter.Write()
这里没有写对象的重载吧,你看看那个类的用法

http://msdn.microsoft.com/zh-cn/library/system.io.binarywriter.write(v=vs.80).aspx

110,570

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧