111,129
社区成员
发帖
与我相关
我的任务
分享
//数据库访问类
namespace RemotingClass
{
public partial class FarClass : Form
{
SqlConnection conn;
public FarClass()
{
InitializeComponent();
conn = new SqlConnection();
conn.ConnectionString = "Data Source=localhost;Database=test;User ID=sa;Password=";
}
public DataTable GetDataTable(string TableName)
{
SqlDataAdapter sda = new SqlDataAdapter("select * from " + TableName, conn);
DataSet ds = new DataSet();
sda.Fill(ds,TableName);
return ds.Tables[TableName];
}
}
}
//服务端
namespace RemotingServer
{
public partial class RemotingServerForm : Form
{
public RemotingServerForm()
{
InitializeComponent();
}
private void RemotingServerForm_Load(object sender, EventArgs e)
{
RemotingConfiguration.Configure("RemotingServer.exe.Config", false);
this.label1.Text = "服务端已启动";
}
}
}
//客户端
namespace RemotingClient
{
public partial class RemotingClientForm : Form
{
FarClass fc;
DataTable table;
public RemotingClientForm()
{
InitializeComponent();
}
private void RemotingClientForm_Load(object sender, EventArgs e)
{
//ChannelServices.RegisterChannel(new TcpChannel());
//WellKnownClientTypeEntry RemotingConfing = new WellKnownClientTypeEntry(typeof(FarClass), "tcp://localhost:9999/TcpService");
//RemotingConfiguration.RegisterWellKnownClientType(RemotingConfing);
RemotingConfiguration.Configure("RemotingClient.exe.Config",false);
fc = new FarClass();
}
private void button1_Click(object sender, EventArgs e)
{
table = new DataTable();
table = fc.GetDataTable("student");
this.dataGridView1.DataSource = table;
}