我正在研究应该执行简单搜索功能的.NET Windows应用程序.应用程序在SQLServer数据库中按序列号搜索某些卡片,这些序列号在文本文件中导入,我只需在文件上打开StreamReader并开始读取行 - 因为每行只包含一个序列.检索数据后,我将它们全部显示在DataGridView上.
文件中的那些连续出版物不按一定的顺序排列(即我做不到Select * from table where serial between( min and max)); 他们完全没有关系.所以不用多说了,这就是我所做的:
DataTable table = new DataTable()
StreamReader stream= new StreamReader(fileName);
while (!stream.EndOfStream) {
string serial = stream.ReadLine();
SqlDataReader reader= GetCardBySerial(serial);
table.Load(reader);
reader.Close();
}
public SqlDataReader GetCardBySerial(string serialNo) {
SqlConnection cnn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("Cards_GetCardBySerial", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@serialNo", SqlDbType.NVarChar).Value = serialNo;
cnn.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
Run Code Online (Sandbox Code Playgroud)
虽然这有效,但对我来说这很慢.应该做些什么来使搜索更快?
| 归档时间: |
|
| 查看次数: |
361 次 |
| 最近记录: |