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的简单理解 ...
随机推荐
- kettle etl
使用注意点 1 如果服务器资源有限的话,尽量少开任务窗口,但是要有容错机制,可以分为按天按分钟 2 如果不想写较长的sql可以用detail来启动 3 在设置每天提交的条数时,如果数据很少,而设置值很 ...
- Ajax跨域请求ashx文件与Webservice文件
前台页面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1 ...
- 部分具有统计功能的TSQL语句(例如DBCC语句,全局函数,系统存储过程)
部分具有统计功能的TSQL语句(例如DBCC语句,全局函数,系统存储过程) 这些功能也能帮助用户了解和监控SQLSERVER的运行情况 DBCC语句,DBCC语句是SQL2005的数据库控制台命令 D ...
- xps 文件操作笔记
1. 在 Silverlight 显示XPS文件,参考:http://azharthegreat.codeplex.com/ 2. Word,Excel, PPT 文件转换为XPS: 参考一(老外写的 ...
- linux下解决端口被占用问题
查找被占用的端口: netstat -tln netstat -tln | grep 8080 查看端口属于哪个程序 lsof -i :8080 杀掉占用端口的进程: kill -9 进程ID ...
- RabbitMQ 连接断开处理-自动恢复
Rabbitmq 官方给的NET consumer示例代码如下,但使用过程,会遇到connection断开的问题,一旦断开,这个代码就会报错,如果你的消费者端是这样的代码的话,就会导致消费者挂掉. u ...
- [OpenCV] 3、直线提取 houghlines
>_<" 发现一个好的链接,是一个讲openCV的网站:http://www.opencv.org.cn/opencvdoc/2.3.2/html/index.html > ...
- [ACM_几何] UVA 11300 Spreading the Wealth [分金币 左右给 最终相等 方程组 中位数]
Problem A Communist regime is trying to redistribute wealth in a village. They have have decided to ...
- Windows 10 技术预览
windows10的技术预览版已经发布了很久了,正式版大约在今年的夏天就会发布,作为微软寄予厚望的下一代全平台操作系统,相比于windows8.1,windows10做了哪些改进,又添加了哪些新功能. ...
- windows下python检查文件是否被其它文件打开.md
有时候我们需要能够判断一个文件是否正在被其它文件访问,几乎不可避免的要调用操作系统接口 from ctypes import cdll import os _sopen = cdll.msvcrt._ ...