fast db 学习
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using FdbDataProvider; namespace DBTest
{
public partial class _Default : System.Web.UI.Page
{
Random r;
SqlConnection sqlConn;
FdbConnection fdbConn;
//SqlCommand sqlCmd;
//FdbCommand fdbCmd;
static int maxIndex = 0; protected void Page_Load(object sender, EventArgs e)
{
r = new Random();
sqlConn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|"
+ @"\SqlServerDB.mdf;Integrated Security=True;User Instance=True");
//sqlConn = new SqlConnection(@"Data Source=SILEAS-PC\SQLFORFASTDB;initial catalog=test;uid=sa;pwd=ss1022");
fdbConn = new FdbConnection(@"DataSource=test.fdb",
FdbConnection.DefaultInitDatabaseSize * 2,
FdbConnection.DefaultInitIndexSize * 2,
FdbConnection.DefaultExtensionQuantum * 2);
//SqlDataSource1.SelectCommand = "SELECT * FROM test";
//SqlDataSource1.Select(new DataSourceSelectArguments());
//maxIndex = ListView1.Items.Count; if (TbxInsert.Text == "")
{
try
{
sqlConn.Open();
fdbConn.Open(); SqlCommand sqlCmd = sqlConn.CreateCommand();
sqlCmd.CommandText = "delete from persons"; FdbCommand fdbCmd = fdbConn.CreateCommand();
fdbCmd.CommandText = "delete from persons"; //where salary>=0"; sqlCmd.ExecuteNonQuery(); fdbCmd.ExecuteNonQuery(); maxIndex = 0;
}
catch (Exception ex)
{
LblError.Text = ex.Message;
}
finally
{
if (sqlConn.State == ConnectionState.Open)
sqlConn.Close();
if (fdbConn.State == ConnectionState.Open)
fdbConn.Close();
}
}
else
{
//maxIndex = Convert.ToInt32(TbxInsert.Text);
}
} protected void BtnSelect_Click(object sender, EventArgs e)
{
try
{
int loopCount = Convert.ToInt32(TbxCount.Text);
int randName;
DateTime startTime, endTime;
TimeSpan d; sqlConn.Open();
LbxSelect.Items.Clear();
LbxDes.Items.Clear(); startTime = DateTime.Now;
for (int i = 0; i < loopCount; ++i)
{
randName = r.Next(0, maxIndex);
SqlCommand sqlCmd = sqlConn.CreateCommand();
//SqlDataSource1.SelectCommand = "SELECT * FROM test WHERE name=" + randName.ToString();
//SqlDataSource1.Select(new DataSourceSelectArguments());
sqlCmd.CommandText = "SELECT * FROM persons WHERE name=" + randName.ToString(); //sqlCmd.ExecuteNonQuery();
//LbxSelect.Items.Add(i.ToString()); SqlDataReader reader = sqlCmd.ExecuteReader(); while (reader.Read())
{
LbxSelect.Items.Add(reader["name"].ToString());
//LbxDes.Items.Add(reader["address"].ToString());
}
reader.Close();
}
endTime = DateTime.Now;
d = endTime - startTime;
LblTime.Text = d.Seconds.ToString() + "秒" + d.Milliseconds.ToString() + "毫秒";
LblError.Text = "SQL Server select successfully!";
}
catch (Exception ex)
{
if (TbxCount.Text == "")
LblError.Text = "请输入查询次数!";
else
LblError.Text = ex.Message;
}
finally
{
sqlConn.Close();
}
} protected void BtnInsert_Click(object sender, EventArgs e)
{
try
{ int count = Convert.ToInt32(TbxInsert.Text), n = 0;
DateTime startTime, endTime;
TimeSpan d;
SqlCommand sqlCmd = sqlConn.CreateCommand();
sqlConn.Open(); startTime = DateTime.Now;
for (int i = 0; i < count; ++i)
{
//SqlCommand sqlCmd = sqlConn.CreateCommand();
sqlCmd.CommandText = "insert into persons(name,salary,address) "
+ "values(" + i.ToString() + "," + i.ToString() + ",'" + TbxDes.Text + "')"; //sqlCmd.CommandText = @"insert into persons(name,salary,address) "
// + @"values(@name,@salary,@address)";
////if (i == 0)
////{
// sqlCmd.Parameters.Add("name", SqlDbType.Int);
// sqlCmd.Parameters.Add("salary", SqlDbType.Real);
// sqlCmd.Parameters.Add("address", SqlDbType.NChar);
////} //sqlCmd.Parameters["name"].Value = i;
//sqlCmd.Parameters["salary"].Value = i;
//sqlCmd.Parameters["address"].Value = "'"+TbxDes.Text+"'"; n += sqlCmd.ExecuteNonQuery();
//SqlDataSource1.InsertCommand = "INSERT INTO test(name, salary, description) "
// + "VALUES (" + i.ToString() + ", " + i.ToString() + ", '" + TbxDes.Text + "')";
//SqlDataSource1.Insert();
}
endTime = DateTime.Now;
d = endTime - startTime;
LblTime.Text = d.Seconds.ToString() + "秒" + d.Milliseconds.ToString() + "毫秒";
maxIndex = Convert.ToInt32(TbxInsert.Text); LblError.Text = "SQL Server Insert " + n.ToString() + " records successfully!";
//maxIndex += count;
}
catch (Exception ex)
{
LblError.Text = ex.Message;
}
finally
{
sqlConn.Close();
}
} protected void BtnClr_Click(object sender, EventArgs e)
{
try
{
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand("DELETE from persons", sqlConn);
int n = sqlCmd.ExecuteNonQuery();
//SqlDataSource1.DeleteCommand = "DELETE from test";
//SqlDataSource1.Delete();
LblError.Text = "SQL Server Clear " + n.ToString() + " records successfully!"; //maxIndex = 0;
}
catch (Exception ex)
{
LblError.Text = ex.Message;
}
finally
{
sqlConn.Close();
}
} //public void FdbCreateTable(FdbConnection connection, FdbCommand command, string name, string[] attr, string[] attrType)
//{
// try
// {
// for (int i = 0; i < attr.Length; ++i)
// {
// CLI.FieldType type; // switch (attr[i])
// {
// case "int": type = CLI.FieldType.cli_int8; break;
// case "real": type = CLI.FieldType.cli_real8; break;
// case "string": type = CLI.FieldType.cli_asciiz; break;
// }
// command.Fields.Add(attr[i], type);
// }
// if (connection.CreateTable(name, command.Fields) >= 0)
// throw new Exception("Cannot create table in FastDB");
// }
// catch (Exception ex)
// {
// LblError.Text = ex.Message;
// }
//} protected void BtnInsertFdb_Click(object sender, EventArgs e)
{
try
{
int count = Convert.ToInt32(TbxInsert.Text), n = 0;
DateTime startTime, endTime;
TimeSpan d;
FdbCommand fdbCmd = fdbConn.CreateCommand();
fdbConn.Open(); startTime = DateTime.Now;
for (int i = 1; i <= count; ++i)
{
//FdbCommand fdbCmd = fdbConn.CreateCommand();
//fdbCmd.CommandText = @"insert into persons(name,salary,address) "
// + @"values(%name,%salary,%address)";
////if (i == 0)
////{
//fdbCmd.Parameters.Add("name", CLI.FieldType.cli_int8, CLI.FieldFlags.cli_indexed);
//fdbCmd.Parameters.Add("salary", CLI.FieldType.cli_int8);
//fdbCmd.Parameters.Add("address", CLI.FieldType.cli_asciiz);
////} //fdbCmd.Parameters["name"].asInt64 = i;
//fdbCmd.Parameters["salary"].asInt64 = i;
//fdbCmd.Parameters["address"].asString = TbxDes.Text; fdbCmd.CommandText = "Insert into persons(name,salary,address) "
+ "values(" + i.ToString() + "," + i.ToString() + ",'" + TbxDes.Text + "')"; n += fdbCmd.ExecuteNonQuery();
}
endTime = DateTime.Now;
d = endTime - startTime;
LblTimeFdb.Text = d.Seconds.ToString() + "秒" + d.Milliseconds.ToString() + "毫秒";
maxIndex = Convert.ToInt32(TbxInsert.Text); LblError.Text = "FastDB Insert " + n.ToString() + " records successfully!";
//maxIndex += count;
}
catch (Exception ex)
{
LblError.Text = ex.Message;
}
finally
{
fdbConn.Close();
}
} protected void BtnSelectFdb_Click(object sender, EventArgs e)
{
try
{
int loopCount = Convert.ToInt32(TbxCount.Text);
int randName;
DateTime startTime, endTime;
TimeSpan d; LbxSelectFdb.Items.Clear();
LbxDesFdb.Items.Clear();
fdbConn.Open(); startTime = DateTime.Now;
for (int i = 0; i < loopCount; ++i)
{
randName = r.Next(0, maxIndex);
//SqlDataSource1.SelectCommand = "SELECT * FROM test WHERE name=" + randName.ToString();
//SqlDataSource1.Select(new DataSourceSelectArguments());
//LbxSelectFdb.Items.Add(randName.ToString());
//LbxDesFdb.Items.Add(TbxDes.Text);
FdbCommand fdbCmd = fdbConn.CreateCommand();
fdbCmd.CommandText = "select * from persons where name=" + randName.ToString(); //fdbCmd.ExecuteNonQuery();
//LbxSelectFdb.Items.Add(i.ToString()); FdbDataReader reader = fdbCmd.ExecuteReader();
while (reader.Read())
{
LbxSelectFdb.Items.Add(reader["name"].ToString());
//LbxDesFdb.Items.Add(reader["address"].ToString());
}
reader.Close();
}
endTime = DateTime.Now;
d = endTime - startTime;
LblTimeFdb.Text = d.Seconds.ToString() + "秒" + d.Milliseconds.ToString() + "毫秒";
LblError.Text = "FastDB Select successfully!";
}
catch (Exception ex)
{
if (TbxCount.Text == "")
LblError.Text = "请输入查询次数!";
else
LblError.Text = ex.Message;
}
finally
{
fdbConn.Close();
}
} protected void BtnClrFdb_Click(object sender, EventArgs e)
{
try
{
FdbCommand fdbCmd = fdbConn.CreateCommand();
fdbCmd.CommandText = "delete from persons where salary >= 0";
fdbConn.Open(); int n = fdbCmd.ExecuteNonQuery();
//SqlDataSource1.DeleteCommand = "DELETE from test";
//SqlDataSource1.Delete();
LblError.Text = "FastDB clear " + n.ToString() + " records successfully!"; //maxIndex = 0;
}
catch (Exception ex)
{
LblError.Text = ex.Message;
}
finally
{
fdbConn.Close();
}
} }
}
fast db 学习的更多相关文章
- Fast RCNN 学习
因为项目需要,之前没有接触过深度学习的东西,现在需要学习Fast RCNN这个方法. 一步步来,先跟着做,然后再学习理论 Fast RCNN 训练自己数据集 (1编译配置) Fast RCNN 训练自 ...
- Fast R-CNN学习总结
Fast R-CNN是R-CNN的改良版,同时也吸取了SPP-net中的方法.在此做一下总结. 论文中讲到在训练阶段,训练一个深度目标检测网络(VGG16),训练速度要比R-CNN快9倍左右,比SPP ...
- 五分钟秒懂Java日志组件
Java中有许多种日志记录方式,有些API有占位符,有些API没占位符,初学的人可能会搞不清楚这些日志组件的由来.我一开始的时候也是很懵逼的,后来一点点弄懂了于是就又了这篇文章. 在Java中进行日志 ...
- mongoDB 文档操作_改
mongoDB 更改操作 格式对比 MySQL update table set .... where .... db.collection.updateOne(query,update,upsert ...
- Quadro P5200 - 最强大的移动工作站显卡 专门为了惠普 VR Z 背包电脑而发布
https://www.leiphone.com/news/201708/Z1MCetuoobEaHIqa.html 前言 在今年的计算机图形技术顶会 SIGGRAPH,英伟达并不是在单纯地展示自家的 ...
- FTP的搭建过程,以及遇到的坑
在之前的博客中,我有说到,我最喜欢用Yum在线安装的方式安装软件,简单省事儿.现在看来,也不尽然,关键是,无法快速找到我要的文件,整个whereis 也很累.所以,现在觉得,还是乖乖的整个压缩包,自行 ...
- torch.nn 的本质
torch.nn 的本质 PyTorch 提供了各种优雅设计的 modules 和类 torch.nn,torch.optim,Dataset 和 DataLoader 来帮助你创建并训练神经网络.为 ...
- Android学习笔记之Fast Json的使用
PS:最近这两天发现了Fast Json 感觉实在是强大.. 学习内容: 1.什么是Fast Json 2.如何使用Fast Json 3.Fast Json的相关原理 4.Fast Json的优势, ...
- Deep Learning 17:DBN的学习_读论文“A fast learning algorithm for deep belief nets”的总结
1.论文“A fast learning algorithm for deep belief nets”的“explaining away”现象的解释: 见:Explaining Away的简单理解 ...
随机推荐
- Windows® 10 Mobile Technical Preview升级方法
就在今天凌晨,微软放出了Windows 10 Mobile Technical Preview的升级,喜欢吃螃蟹的人总是希望可以在第一时间尝试新的系统,我也不例外. 本次升级涵盖了从Lumia 520 ...
- (Gym 100685G) Gadget Hackwrench(LCA在线ST)
Gadget Hackwrench time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...
- codeforces 425E
题意:对于[l1, r1], [l2, r2]...[lm, rm]线段组成的一个集合S,我们定义f(S)为最大的不相交(没有任何公共点)线段数,现在给定n及k,n表示线段范围,即任何[li, ri] ...
- PostgreSQL学习记录-- 2016-03-11
1.日期字段 “年月日” 使用 date “年月日 时分秒” 使用 timestamp without time zone 2.布尔字段 使用 boolean 3.字符字段 使用 character ...
- HttpLib - 一个对 Http 协议进行封装的库
今日,在 Codeplex 上看到一个开源项目,对 Http 协议进行了封装,这下可以方便这些在 .NET 平台下访问 Web 服务器的同学们了,比如,从 Web 服务器抓取一个页面,使用 .NET ...
- maven 打包 xml文件
说起来手贱啊,搞了两个小时,就是因为打包的时候,maven无法把xml文件打包到正确的位置. 本来应该是打包到 com/presistence包下,结果打出来有两个包,一个是com/presisten ...
- 微软 PowerShell Script Explorer 满血复活,正式发布
一年前的今天,微软在其Windows PowerShell官方博客声明中止 ‘Script Explorer’ 应用程序的开发. 一年后的今天,微软为其Script Explorer注入了新的生命.一 ...
- 使用ThreadSanitizer线程检查工具
ThreadSanitizer又叫TSan,是一个检查线程Data Race的C/C++工具.它集成在新版的gcc和clang中,通过编译时加-fsanitize=thread,可以在运行时检测出Da ...
- Qt5.3 打印示例时出现错误
说明:今天我在用Qt5.3写打印文档的时候,编译出错了,出错代码为: C:\Users\joe\Desktop\5-9\myPrint\mainwindow.cpp:35: error: undefi ...
- java web面试题,收集
java面试题: http://www.codeceo.com/article/java-interview-question.html(很多题都很废) http://www.php100.com/h ...