高手请告诉俺,俺可真给分呀!
//这是前端的代码
private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == (char)13)
//设定一个新的网格
{
this.dataGrid1.DataMember="";
DataSet ds=new DataSet();
//da.Fill(ds);
//c代表我的组件对象
//c.reg_no是组件内的一个属性用来给查询语句条件的
c.reg_no =textBox2.Text;
//ds是我想传递过去一个记录集对象或返回一个记录集对象好让网格接收数据.
c.QueryStock(ds);
dataGrid1.DataSource=ds.DefaultViewManager;
}
}
后端的代码
using System;
using System.Data.OleDb;
using System.Data;
using System.Runtime.InteropServices;//为了调用GUID
//using System.EnterpriseServices;//引用COM+的类
//using System.Web.Services;
[Guid("539448DE-9F3B-4781-A1F6-F3C852091FC9")]
public interface Query
{
bool QueryStock( object reader);
string reg_no //Property: Name, Get/Set
{
get;
set;
}
}
namespace COMLibrary
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class Class1:Query
{
private static string strConnect ="Provider=MSDAORA.1;Password=erpii;User ID=erpii;Data Source=erpii;Persist Security Info=True";
private OleDbConnection conConnection = new OleDbConnection ( strConnect ) ;
// OleDbDataReader reader ;
//string strCommand = "SELECT distinct * FROM et_stock_reg_d_iv" ;
//OleDbCommand cmd = new OleDbCommand ( strCommand , conConnection ) ;
// reader = cmd.ExecuteReader ( ) ;//获得数据集
public bool QueryStock ( object reader)
{
string StrSql="select * from et_inside_bs where like regno % " + reg_no + "%";
conConnection.Open(); // 打开数据连接
OleDbCommand cmd = new OleDbCommand ( StrSql , conConnection ) ;
//
//// conConnection.ConnectionString=strConnect;
// conConnection.Open();
OleDbDataAdapter da=new OleDbDataAdapter(StrSql,conConnection);
DataSet ds=new DataSet();
// da.Fill(ds);
reader=ds;
conConnection.Close();
conConnection.Dispose();
return true;
}
private string mreg_no;
public string reg_no //Property: Name, Get/Set
{
get { return mreg_no; }
set { mreg_no = value; }
}
public Class1()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
}
}
可是怎么才能把记录返回来?那位高手告诉俺重重有分哪!