请教操作SQL SERVER的问题
我的程序如下,为什么我在循环里调govclass.Getgovmastbygjcode,第一次很正常,但第二次就显示服务器超时?
this.sqlConnection1.Open();
SqlTransaction myTrans;
myTrans=this.sqlConnection1.BeginTransaction();
this.sqlCommand1.Transaction=myTrans;
try
{
for(Line=din.ReadLine();Line!=null;Line=din.ReadLine())
{
str=Line.Split(' ');
if(!govclass.Getgovmastbygjcode(str[3],out tgovmast))
{
this.Label6.Text="无此单位:"+str[3];
errflag=true;
break;
}
this.sqlCommand1.CommandText="insert into edutable values '"+tedu.edu_date+"','"+tedu.orgidt+"','"+tedu.yjname+"','"+tedu.yjgjcode+"','"+tedu.govname+"','"+tedu.gjcode+"','"+tedu.czcode+"','"+tedu.kmlei+"','"+tedu.kmkuan+"','"+tedu.kmxiang+"','"+tedu.kmname+"','"+tedu.xmcode+"','"+tedu.xmname+"','"+tedu.accname+"','"+tedu.openbank+"','"+tedu.accno+"',"+tedu.eduamt.ToString()+","+tedu.useamt.ToString()+")";
this.sqlCommand2.CommandText="update govmast set yearamt=yearamt+"+tedu.eduamt.ToString()+" where gjcode='"+tedu.gjcode+"'";
this.sqlCommand1.ExecuteNonQuery();
this.sqlCommand2.ExecuteNonQuery();
}
public bool Getgovmastbygjcode(string ingjcode,out govmast ingovmast)
{
bool rc=false;
System.Data.SqlClient.SqlConnection trcnosqlConnection=new System.Data.SqlClient.SqlConnection(dbstr);
System.Data.SqlClient.SqlCommand trcnosqlCommand=new System.Data.SqlClient.SqlCommand("select * from govmast where gjcode='"+ingjcode+"'");
InitGovmast(out ingovmast);
try
{
trcnosqlConnection.Open();
trcnosqlCommand.Connection=trcnosqlConnection;
System.Data.SqlClient.SqlDataReader
reader=trcnosqlCommand.ExecuteReader();
if(reader.Read())
{
ingovmast.useamt=double.Parse(reader["useamt"].ToString());
rc=true;
}
reader.Close();
}
catch(Exception err)
{
trcnosqlConnection.Close();
return false;
}
trcnosqlConnection.Close();
return rc;
}