以下是我获取企业信息的一段代码//注 这个文件为*.CS里的代码
public static void company_getcompanyinfo()
{
read =get_dataset("select * from company where accountid=" + states.session_Overtime(sll.split(Convert.ToString(HttpContext.Current.Session["account"]), 1)));
if (read.Tables[0].Rows.Count > 0)
{
c_companyname.Text = read.Tables[0].Rows[0]["companyname"].ToString();
c_contactperson.Text = read.Tables[0].Rows[0]["contactperson"].ToString();
c_tel.Text = read.Tables[0].Rows[0]["tel"].ToString();
c_fax.Text = read.Tables[0].Rows[0]["fax"].ToString();
c_net.Text = read.Tables[0].Rows[0]["net"].ToString();
c_email.Text = read.Tables[0].Rows[0]["email"].ToString();
c_msn.Text = read.Tables[0].Rows[0]["msn"].ToString();
c_qq.Text = read.Tables[0].Rows[0]["qq"].ToString();
c_address.Text = read.Tables[0].Rows[0]["address"].ToString();
c_postcode.Text = read.Tables[0].Rows[0]["postcode"].ToString();
}
else
{
prompt.alert_oflocation("提示:操作失败!可能原因为未查找到企业信息!", "iframe_ofindex.aspx");
}
read = null;
}
#endregion我有很多页面*.aspx.cs文件里想都调用这个函数,我都做company_getcompanyinfo()静态调用,但执行到这c_companyname.Text 提示我:CS0103: 当前上下文中不存在名称“c_companyname”.我也想做返回值,但函数只能返回一个返回值,我需要返回很多有很多地方都需要调用企业信息,都要调用这个代码,我还不想每个地方都写,只想写一个然后调用,请问该如何解决呢 ?(注:不使用自定义控件的方法),请问该如何解决()
public static void company_getcompanyinfo()
{
read =get_dataset("select * from company where accountid=" + states.session_Overtime(sll.split(Convert.ToString(HttpContext.Current.Session["account"]), 1)));
if (read.Tables[0].Rows.Count > 0)
{
c_companyname.Text = read.Tables[0].Rows[0]["companyname"].ToString();
c_contactperson.Text = read.Tables[0].Rows[0]["contactperson"].ToString();
c_tel.Text = read.Tables[0].Rows[0]["tel"].ToString();
c_fax.Text = read.Tables[0].Rows[0]["fax"].ToString();
c_net.Text = read.Tables[0].Rows[0]["net"].ToString();
c_email.Text = read.Tables[0].Rows[0]["email"].ToString();
c_msn.Text = read.Tables[0].Rows[0]["msn"].ToString();
c_qq.Text = read.Tables[0].Rows[0]["qq"].ToString();
c_address.Text = read.Tables[0].Rows[0]["address"].ToString();
c_postcode.Text = read.Tables[0].Rows[0]["postcode"].ToString();
}
else
{
prompt.alert_oflocation("提示:操作失败!可能原因为未查找到企业信息!", "iframe_ofindex.aspx");
}
read = null;
}
#endregion我有很多页面*.aspx.cs文件里想都调用这个函数,我都做company_getcompanyinfo()静态调用,但执行到这c_companyname.Text 提示我:CS0103: 当前上下文中不存在名称“c_companyname”.我也想做返回值,但函数只能返回一个返回值,我需要返回很多有很多地方都需要调用企业信息,都要调用这个代码,我还不想每个地方都写,只想写一个然后调用,请问该如何解决呢 ?(注:不使用自定义控件的方法),请问该如何解决()
解决方案 »
- 异常详细信息: System.InvalidOperationException: Fill: SelectCommand.Connection 属性尚未初始化
- GridView删除某一行的写法
- 为什么提示OleDbDataReader reader = cmd.ExecuteReader(); 这句标准表达式中数据类型不符?
- 五一了,奢嗜一回,散分。捎带问个小问题
- <%# DataBinder.Eval(Container.DataItem, "id")%>
- 大家知道什么地方有提供NT下载的吗?
- 求助,关于ASP.NET中使用存储过程返回数据集问题,再现等待
- asp.net mvc 中 formsauthentication如何实现多种角色同时登录
- 关于asp.net应用程序打包时怎样把sql server数据库一起打包??
- js选中该行上下移动
- ---------------关于获得ds的行数的问题,在线等
- 远程访问,forms认证问题
---------------
返回企业类型的实例,字段封装的类型的属性中即可
如:
public static company company_getcompanyinfo()
但函数只能返回一个返回值,我需要返回很多有很多地方都需要调用企业信息,都要调用这个代码
---------------
返回企业类型的实例,字段封装的类型的属性中即可
如:
public static company company_getcompanyinfo()
楼上兄弟。哎 一工就那点代码 你全了
---------------------------------------------------------
你可以将company_getcompanyinfo()写成只返回dataset或datatable等。然后再将数据源绑定到控件上。
2。c_companyname.Text没有,要先定义
public static company_getcompanyinfo(TextBox c_companyname,TextBoxc_contactperson,....(几个几个类似参数全部写上))
{
read =get_dataset("select * from company where accountid=" + states.session_Overtime(sll.split(Convert.ToString(HttpContext.Current.Session["account"]), 1)));
if (read.Tables[0].Rows.Count > 0)
{
c_companyname.Text = read.Tables[0].Rows[0]["companyname"].ToString();
c_contactperson.Text = read.Tables[0].Rows[0]["contactperson"].ToString();
c_tel.Text = read.Tables[0].Rows[0]["tel"].ToString();
c_fax.Text = read.Tables[0].Rows[0]["fax"].ToString();
c_net.Text = read.Tables[0].Rows[0]["net"].ToString();
c_email.Text = read.Tables[0].Rows[0]["email"].ToString();
c_msn.Text = read.Tables[0].Rows[0]["msn"].ToString();
c_qq.Text = read.Tables[0].Rows[0]["qq"].ToString();
c_address.Text = read.Tables[0].Rows[0]["address"].ToString();
c_postcode.Text = read.Tables[0].Rows[0]["postcode"].ToString();
}
else
{
prompt.alert_oflocation("提示:操作失败!可能原因为未查找到企业信息!", "iframe_ofindex.aspx");
}
read = null;
}
#endregion
2\返回dataset或datatable,个人觉得不太合适.
3\使用引用传递,即byref
4\不嫌麻烦的话还可以写载重