请教操作SQL SERVER的问题

kmyangyl 2003-01-17 09:13:09
我的程序如下,为什么我在循环里调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;
}
...全文
65 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kmyangyl 2003-01-17
  • 打赏
  • 举报
回复
因为我的函数是在外面,我要去调
icyer 2003-01-17
  • 打赏
  • 举报
回复
为什么要在循环里面打开Connection呢?可以在循环外打开呀,这样就不会频繁的Open、Close了
wqhai 2003-01-17
  • 打赏
  • 举报
回复
我也出现过类似的问题,还没有解决
呵呵……等待中……

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧