高手请告诉俺,俺可真给分呀!

sunjian5188 2002-11-05 03:04:02
//这是前端的代码
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: 在此处添加构造函数逻辑
//
}

}
}
可是怎么才能把记录返回来?那位高手告诉俺重重有分哪!
...全文
22 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
TheAres 2002-11-06
  • 打赏
  • 举报
回复
简单举例如下,首先建议接口用I开头,看起来不舒服.

1.实现
public interface IQuery
{
bool QueryStock(DataSet myDS);

}

class DBsource:IQuery
{
public bool QueryStock(DataSet myDS)
{

string strConn = "Provider=SQLOLEDB;Data Source=(local);" +
"Initial Catalog=Northwind;Trusted_Connection=Yes;";
string StrSql="select * from customers";

OleDbConnection conConnection = new OleDbConnection(strConn);
conConnection.Open(); // 打开数据连接
OleDbDataAdapter da = new OleDbDataAdapter(StrSql,conConnection);

da.Fill(myDS);

conConnection.Close();
conConnection.Dispose();
return true;
}
}
调用:
DBsource mydbsource = new DBsource();
DataSet ds = new DataSet();
mydbsource.QueryStock(ds);

this.dataGrid1.DataSource = ds.DefaultViewManager;
shenanigan 2002-11-05
  • 打赏
  • 举报
回复
UP一下吧,我是刚开始学C#的

111,116

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧