如何在aspx页面上使用数据表? [英] How to use datatable at aspx page ?

查看:62
本文介绍了如何在aspx页面上使用数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public boolean ex_gg(ref string vin(), ref string vout(),ref string verr()) 
{ 
  DataTable Dt = new DataTable(); 
try 
{ 
///fill datatable ObjDT 
} 
catch 
{ 
// error msg 
} 
return true; 
}


ex_gg() 在class.cs文件中定义.现在,如果返回类型为true,那么我想在aspx页面上使用ObjDT DataTable.
如何在那里使用ObjDT?请帮帮我.


ex_gg() is defined in class.cs file. Now if return type is true then I want to use ObjDT DataTable at aspx page.
How can I use ObjDT there? please help me.

推荐答案

使用像这样
在Class.cs中创建函数

public DataTable ex_gg(参考字符串vin(),参考字符串vout(),参考字符串verr())
{
DataTable Dt =新的DataTable();
试试
{

///填写数据表ObjDT
return dt;
}
捕获(System.Exception ex)
{
抛出新的Exception(ex.Message);
}
}

在aspx页面中,只要您想使用它,就可以使用它

Class cls = new Class();
数据表dt = cls.ex_gg(param1,....);
if(dt.Rows.Count> 0)
{

}
use like it
Make Function in Class.cs

public DataTable ex_gg(ref string vin(), ref string vout(),ref string verr())
{
DataTable Dt = new DataTable();
try
{

///fill datatable ObjDT
return dt;
}
catch (System.Exception ex)
{
throw new Exception(ex.Message);
}
}

in aspx page use like it whereever u want to use

Class cls=new Class();
DataTable dt=cls.ex_gg(param1,....);
if(dt.Rows.Count>0)
{

}


好吧,为什么不将返回类型设为布尔值(是或否),为什么不填写数据表并使用"Datatable"作为返回类型.
您始终可以计算表中的行数.如果有错误(返回空表)或没有数据,则行数将为零.
如果不为零,请使用返回的填充数据表.
Well, instead of having a return type as boolean (true or false), why not fill the datatable and use ''Datatable'' as return type.

You can always count the number of rows in the table. If there is an error(return empty table) or no data then row count would be zero.
If it''s not zero, use the returned filled datatable.


这篇关于如何在aspx页面上使用数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆