namespace SSer
{
public class ResultData:DataSet
{
public const String RESULT_TABLE = "RESULT";
public const String MTRLNO_FIELD     = "MtrNo";
public const String LOCDESC_FIELD     = "LocDesc";
public const String MTRTYPE_FIELD     = "MtrType";
public const String STDUNIT_FIELD     = "StdUnit";
public const String CRTTIME_FIELD     = "CrtTime";
private ResultData(SerializationInfo info, StreamingContext context) : base(info, context) { }
public ResultData()
{
BuildDataTables();
}
private void BuildDataTables()
{
DataTable     table   = new DataTable(RESULT_TABLE);
DataColumnCollection columns = table.Columns;
        columns.Add(MTRLNO_FIELD, typeof(System.String));
columns.Add(LOCDESC_FIELD, typeof(System.String));
columns.Add(MTRTYPE_FIELD, typeof(System.String)).AllowDBNull= false;
columns.Add(STDUNIT_FIELD, typeof(System.String)).AllowDBNull= false;
columns.Add(CRTTIME_FIELD, typeof(System.DateTime)).AllowDBNull= false;       this.Tables.Add(table);
}
}
public class Dataconnect : IDisposable
{
private SqlDataAdapter dsCommand;
public Dataconnect()
{
dsCommand = new SqlDataAdapter();
dsCommand.SelectCommand = new SqlCommand();
dsCommand.SelectCommand.Connection  = new SqlConnection(System.Configuration .ConfigurationSettings .AppSettings["sqllink"]);
dsCommand.TableMappings.Add("Table", ResultData.RESULT_TABLE);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true); // as a service to those who might inherit from us
}
protected virtual void Dispose(bool disposing)
{
if (! disposing)
return; // we're being collected, so let the GC take care of this object
if (dsCommand != null )
{
if (dsCommand.SelectCommand != null)
{
if( dsCommand.SelectCommand.Connection != null)
dsCommand.SelectCommand.Connection.Dispose();
dsCommand.SelectCommand.Dispose();
}
dsCommand.Dispose();
dsCommand = null;
}
}
private void InitializeComponent()
{}  
public ResultData GetMtrlByMtrlNo(string MtrlNo )
{
return FillResultData("GetMtrlByMtrlNo", "@MtrlNo", MtrlNo);
}
private ResultData FillResultData(String commandText, String paramName, String paramValue)
{
if (dsCommand == null )
{
throw new System.ObjectDisposedException( GetType().FullName );
}            
ResultData   data    = new ResultData();
SqlCommand command = dsCommand.SelectCommand; command.CommandText = commandText;
command.CommandType = CommandType.StoredProcedure; // use stored proc for perf
SqlParameter param = new SqlParameter(paramName, SqlDbType.NVarChar, 255);
param.Value = paramValue;
command.Parameters.Add(param);            
dsCommand.Fill(data);
return data;
}
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient ;
using System.Data .SqlTypes;
using SSer;
namespace SBYcan
{
public class query : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button cmdQuit;
protected System.Web.UI.WebControls.Button cmd_Print;
protected System.Web.UI.WebControls.Button cmdQuery;
protected System.Web.UI.WebControls.DropDownList drplst_mtrlno;
protected System.Web.UI.WebControls.Label lblMtrlNo;
protected System.Web.UI.HtmlControls.HtmlGenericControl FONT1;
protected System.Web.UI.HtmlControls.HtmlGenericControl FONT2;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void cmdQuery_Click(object sender, System.EventArgs e)
{
string s,MtrlNo;
s =drplst_mtrlno.SelectedItem .Value;
MtrlNo=s;
if(s !="")
{
DataGrid1.DataSource =GetMtrlByMtrlNo(string MtrlNo );//问题在于如何调用web方法 DataGrid1.DataBind ();
// }
else Response.Write ("<script>'window.alert('查询条件不能为空,请选择查询条件!')'<script>");
}
我首先定义了一个Service,SSer,但不知道怎么用访问它。我的设想是通过SSer的方法到MtrlMain表中查询Mtrl的详细信息,利用的事存储过程查询的,但是不知道怎么把结果返回给应用程序中的DataGrid。请各位大侠帮忙!!