这是我的代码,请看一下,感谢各位高手,我很着急,从头学,已做了3天了
public partial class Form1 : Form
{
string filename = @"\Program Files\SQLMobile\sqlmobile.sdf";
string CumputerName = @"ElvisGao";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DeleteDB();
Sync();
if (snapshotDataSetUtil.DesignerUtil.IsRunTime())
{
this.userInfoTableAdapter.Fill(this.snapshotDataSet.UserInfo);
}
}
private void Sync()
{
SqlCeReplication repl = new SqlCeReplication();
repl.InternetUrl = @"http://localhost/sqlmobile/sqlcesa30.dll";
repl.Publisher = CumputerName;
repl.PublisherDatabase = @"SQLMobile";
repl.PublisherSecurityMode = SecurityType.NTAuthentication;
repl.Publication = @"SQLMobile";
repl.Subscriber = @"SQLMobile";
repl.SubscriberConnectionString = @"Data Source='" + filename + "';Password='';Max Database Size='128';Default Lock Escalation ='100';";
try
{
repl.AddSubscription(AddOption.CreateDatabase);
repl.Synchronize();
}
catch (SqlCeException e)
{
MessageBox.Show(e.ToString());
}
}
private void DeleteDB()
{
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
}
private void newMenuItemMenuItem_Click(object sender, EventArgs e)
{
userInfoBindingSource.AddNew();
SQLMobile.UserInfoEditViewDialog userinfoEditViewDialog = SQLMobile.UserInfoEditViewDialog.Instance(this.userInfoBindingSource);
userinfoEditViewDialog.ShowDialog();
}
private void userInfoDataGrid_Click(object sender, EventArgs e)
{
SQLMobile.UserInfoSummaryViewDialog userinfoSummaryViewDialog = SQLMobile.UserInfoSummaryViewDialog.Instance(this.userInfoBindingSource);
userinfoSummaryViewDialog.ShowDialog();
}
}