我正在将数据库中的2个值作为displaymember和valuemember加载到我的组合框中。
这是我的代码:
def factorial(x):
if x <= 1:
return x
return x * factorial(x - 1)
def factorialSum(start, end):
sum = 0
for x in range(start, end + 1):
sum += factorial(x)
return sum
n1 = int(input("Enter a number: "))
n2 = int(input("Enter 2nd Number: "))
if n2 < n1:
print "The second number should be greather than first number"
else:
print(factorialSum(n1, n2))
在我的数据库中,我有大约10k行,并且它使用此函数加载大约67ms。有没有更快的方法这样做,因为我的private void LoadPartners()
{
using (FbConnection con = new FbConnection(Properties.Resources.connectionString_EB))
{
con.Open();
using (FbCommand cmd = new FbCommand("SELECT PARTNERID, PARTNERNAME FROM PARTNERS", con))
{
List<Int_String> list = new List<Int_String>();
FbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
list.Add(new Int_String { _int = Convert.ToInt32(dr[0]), _string = dr[1].ToString() });
}
partner_cmb.DataSource = list;
partner_cmb.ValueMember = "_int";
partner_cmb.DisplayMember = "_string";
}
con.Close();
}
} //Load all partners inside combobox
需要大约70毫秒,而另外一个函数是相同的,因此总共这3个函数执行210毫秒,而对于其他较小的函数,我的表单大约需要2秒来加载我的表单这令人沮丧。有没有办法让这个功能更快地工作?