C#链接Oracle数据库 查询功能 最简单的用户名密码登陆(通过OracleClient)connection, command,reader

在开始之前,请确保你已经有数据库的账户,包括用户名、密码
而且创建好了一个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=&quot;(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL=TCP)(HOST=localhost)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME=orcl)))&quot;;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"
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值