在开始之前,请确保你已经有数据库的账户,包括用户名、密码
而且创建好了一个table
我的table叫userinfo,里面有userid和userpassword两个域。
打开一个新的Project
1. 在C#里添加OracleClient
Reference - Add Reference
搜索框搜Oracle
勾选System.Data.OracleClient
2. 写app.config
注意:把connectionString里的password和userid都要改成你自己的数据库登录名、密码。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source="(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL=TCP)(HOST=localhost)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME=orcl)))";Persist Security Info=True;User ID=*****;Password=*****;Unicode=True" providerName="System.Data.OracleClient" />
</connectionStrings>
</configuration>
3. xaml设计页面
这个很简单,visual studio可以直接拖拽设置。
我的长这个样子:
<Window x:Class="WpfApp3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp3"
mc:Ignorable="d"
Title="MainWindow" Height="450"