各位高手帮帮忙对你来说一定简单我是刚学C# C#是面向对象的,当你创建了一个连接数据库的类时,必须在调用前实例化,比如: Class1 aaa=new Class1();不大清楚你为什么要用interface,用CLASS建一个基类不是很好吗 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的继承自接口的类已经写好了,直接用就可以了。COMLibrary.Class1 c1 = new COMLibrary.Class1();System.Object obj = new System.Object();if c1.QueryStock(obj,"a string"){}不过看起来好奇怪,你的这个方法有两个参数,可以都没有使用。所以上面的参数也不知道该传人什么。而且无论什么情况都返回true,实在费解。public bool QueryStock (object reader,string strCommand){ conConnection.Open(); // 打开数据连接 OleDbCommand cmd = new OleDbCommand ( strCommand , conConnection ) ; return true;} public bool QueryStock (object reader,string strCommand){ conConnection.Open(); // 打开数据连接 OleDbCommand cmd = new OleDbCommand ( strCommand , conConnection ) ; return true;}这里我是不知道应该怎么写,我的本意是前端传递一个记录集和一个查询字符串或条件,但是怎么也返不回来我把参数改成了public bool QueryStock (out object reader,ref string strCommand)但是也不行能不能告诉我,谢谢解决马上给分. //这是前端的代码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: 在此处添加构造函数逻辑 // } }}可是怎么才能把记录返回来?那位高手告诉俺重重有分哪! 简单举例如下,首先建议接口用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; 如何抓取HTML页面数据 分享读取各大主流邮箱通讯录(联系人)、MSN好友列表的的功能[2.0版]预告贴 catch (Exception ex) 请问如何能自定义VS2005的代码分析规则? 请问 dataset.xsd 与工具箱中的 DataSet 有什么区别 程序框架设计 求助:VS2008远程调试“出现了特定的安全程序包错误” 用短信猫的比较难问题 请高手指教用c#做出xp风格的界面 C#中ListView的显示问题 各位高手请高在C#中编写组件怎么写! 高手请告诉俺,俺可真给分呀!
System.Object obj = new System.Object();
if c1.QueryStock(obj,"a string")
{
}不过看起来好奇怪,你的这个方法有两个参数,可以都没有使用。所以上面的参数也不知道该传人什么。而且无论什么情况都返回true,实在费解。public bool QueryStock (object reader,string strCommand)
{
conConnection.Open(); // 打开数据连接
OleDbCommand cmd = new OleDbCommand ( strCommand , conConnection ) ;
return true;
}
{
conConnection.Open(); // 打开数据连接
OleDbCommand cmd = new OleDbCommand ( strCommand , conConnection ) ;
return true;
}
这里我是不知道应该怎么写,我的本意是前端传递一个记录集和一个查询字符串或条件,但是怎么也返不回来我把参数改成了public bool QueryStock (out object reader,ref string strCommand)但是也不行能不能告诉我,谢谢解决马上给分.
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: 在此处添加构造函数逻辑
//
} }
}
可是怎么才能把记录返回来?那位高手告诉俺重重有分哪!
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;