mysql的mvvm,使用MVVM设计模式连接到WPF中的数据库

I am a beginner at MVVM design patter and WPF I am trying to make a small example of connection to the MS Access database using the WPF and MVVM Light Toolkit patter design. but when i run the program it does not do anything and when i debug i find that the instruction stops at the instruction level.con.Open();

model / DataConnection.cs file and then it goes to MainWindow.xaml.cs.

I do not find why he does not continue the execution of all the instructions?

What I have tried:

Model / DataConnection.cs

public class DataConnection

{

public void OpenConnection()

{

OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=db.accdb;" +

"Persist Security Info=False;");

OleDbCommand cmd = con.CreateCommand();

cmd.CommandText = "Insert into table (num,nom)Values(123,'nom1')";

cmd.Connection = con;

con.Open();

cmd.ExecuteNonQuery();

MessageBox.Show("Record Submitted", "Congrats");

}

}

ViewModel / MainViewModel.cs

public class MainViewModel : ViewModelBase

{

private DataConnection _dataconnection;

public MainViewModel(DataConnection dataconnexion)

{

_dataconnection = dataconnexion;

_dataconnection.OpenConnection();

}

}

ViewModel / ViewModelLocator.cs

public class ViewModelLocator

{

static ViewModelLocator()

{

ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

SimpleIoc.Default.Register();

SimpleIoc.Default.Register();

}

public MainViewModel Main

{

get

{

return ServiceLocator.Current.GetInstance();

}

}

/// ///Cleans up all the resources. /// public static void Cleanup()

{

}

}

解决方案It says that because you don't have either an appropriate architecture of Office installed or Access Runtime[^] installed on the machine.

If your app is compiled AnyCPU and running on a 64-bit machine, you'd have to use the 64-bit Office or Runtime.

If your app is compiled AnyCPU and running on a 32-bit machine, you'd have to use the 32-bit Office or Runtime.

If your app is compiled x86, you have to have the 32-bit Office or Runtime installed.

If your app is compiled x64, you have to have the 64-bit Office or Runtime installed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值