1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
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();
}
}
}
} |