linux mono 调用windows sqlServer 2005
1. 实现linux mono Develop中调用windows 中的ql Server 2005
l linux 与 windows 在一个局域网的网段中
l windows 中安装 sql Server 2005
2. windows 中的设置
l sql sever 2005 northwin数据库
1.1 product结构
1.2 Categories 结构
2 如果本机的防火强开启,请关闭。如果防火墙开启,windows会阻止linux的访问
3. Linux中的设置
3.1 Ping windows 的IP ,确认linux 可访问windows
3.2 界面设计
3.2.1 数据与PropertyGrid绑定界面
3.2.2 数据与gridView绑定界面
3.3 代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WinMonoApp
{
public partial class frmWFBrowse : Form
{
SqlDataAdapter myDataAdapter = null;
//List<bindPropertyData> bindPropertyList = null;
string myConnectionString = null;
string sqlProduct = "SELECT * FROM [Northwind].[dbo].[Products] ";
string sqlCategory = "SELECT [CategoryID],[CategoryName],[Description] FROM [Northwind].[dbo].[Categories] ";
DataSet myCategory = new DataSet();
DataSet myProduct = new DataSet();
public frmWFBrowse()
{
InitializeComponent();
}
private void btnOK_Click(object sender, EventArgs e)
{
myConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["WinMonoApp.Properties.Settings.BPMDBConnectionString"].ConnectionString;
//MessageBox.Show(myConnectionString);
myDataAdapter = new SqlDataAdapter(sqlCategory, myConnectionString);
myDataAdapter.Fill(myCategory);
myDataAdapter.SelectCommand.CommandText = string.Format(sqlProduct );
myDataAdapter.Fill(myProduct);
//MessageBox.Show(myDs.Tables[0].Rows.Count.ToString());
this.FillTemplate();
}
private void FillTemplate()
{
try
{
if(myCategory.Tables.Count!=0)
{
this.lbTemplate.DisplayMember = "CategoryName";
this.lbTemplate.DataSource = myCategory.Tables[0];
}
}
catch(Exception myEx)
{
MessageBox.Show(myEx.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void lbTemplate_SelectedIndexChanged(object sender, EventArgs e)
{
var wfv = this.lbTemplate.SelectedItem as DataRowView ;
if (wfv != null)
{
this.llDeleteTemplate.Enabled = true;
this.pgTemplateV.SelectedObject = wfv;
DataRow[] myProductList=myProduct.Tables[0].Select(string.Format("CategoryID={0}",wfv.Row.ItemArray[0]));
this.pgTemplateInfo.SelectedObjects = myProductList;
DataTable myDataTable = myProductList[0].Table.Clone();
myDataTable.Rows.Clear();
foreach (var row in myProductList)
{
myDataTable.ImportRow(row );
}
this.dgvBindProperty.DataSource = myDataTable ;
}
}
private void frmWFBrowse_Load(object sender, EventArgs e)
{
this.llDeleteTemplate.Enabled = false;
}
private void llDeleteTemplate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
}
}
}
3.4 App.config
<connectionStrings>
<add name="WinMonoApp.Properties.Settings.BPMDBConnectionString" connectionString="Data Source=10.168.14.131;Initial Catalog=Northwind;User ID=sa;Password=sqlsa" providerName="System.Data.SqlClient"/>
</connectionStrings>
3.5 运行效果
3.5.1 PropertyGrid绑定效果
3.5.2 PropertyGrid子项编辑
3.5.3 GridView绑定效果
转载于:https://www.cnblogs.com/hbb0b0/archive/2009/06/10/1500789.html