当前位置: 代码迷 >> ASP.NET >> 这个函数有什么东东吗
  详细解决方案

这个函数有什么东东吗

热度:5685   发布时间:2013-02-26 00:00:00.0
这个函数有什么错误吗?
//根据单位名称计算其ID
private   string   GetOrganID(string   strOrg)
{
string   id= "20 ";
SqlConnection   Conn=new   SqlConnection(ConnStr);
string   strSql= "select   id   from   clientele   where   organ= "+strOrg.Trim();
SqlCommand   cmd=new   SqlCommand(strSql,Conn);
Conn.Open();
try
{
SqlDataReader   dr=cmd.ExecuteReader();
if(dr.Read())
{
id=dr[ "id "].ToString().Trim();
}
dr.Close();
}
catch(SqlException   Ex)
{
Response.Write(Ex.ToString());
}
finally
{
Conn.Close();
}
return   id;
}

private   void   Button1_Click(object   sender,   System.EventArgs   e)
{
string   strOrg=DropDownList4.SelectedItem.Text.ToString().Trim();
Response.Write( " <script> alert( 'ID= '+ ' "+   GetOrganID(strOrg)   + " '); </script> ");
}

------解决方案--------------------------------------------------------
string strSql= "select id from clientele where organ= ' "+strOrg.Trim()+ " ' ";
如果organ是nvarchar类型的话

------解决方案--------------------------------------------------------
string strSql= "select id from clientele where organ= "+strOrg.Trim();===> string strSql= "select id from clientele where organ= ' "+strOrg.Trim() + " ' ";
  相关解决方案