using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MyWinForm5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Visible = false;
UserID.TabIndex = 0;
PWD.TabIndex = 1;
PWDFRIM.TabIndex = 2;
Man.TabIndex = 3;
Women.TabIndex = 4;
vacation.TabIndex = 5;
Add.TabIndex = 6;
Exit.TabIndex = 7;
Delete.Visible = false;
Save.Visible = false;
}
/// <summary>
/// 隐藏注册界面,显示表数据
/// </summary>
#region
public void HideAdd()
{
dataGridView1.Visible = true;
UserID.Visible = false;
UserName.Visible = false;
PassWord.Visible = false;
PWD.Visible = false;
PWDFRIM.Visible = false;
PasswordFirm.Visible = false;
Sex.Visible = false;
Man.Visible = false;
Women.Visible = false;
Job.Visible = false;
vacation.Visible = false;
Add.Visible = false;
Exit.Visible = false;
Save.Visible = true;
Delete.Visible = true;
}
#endregion
/// <summary>·
/// 显示注册界面,隐藏表数据
/// </summary>
#region
public void ShowAll()
{
Save.Visible = false;
Delete.Visible = false;
dataGridView1.Visible = false;
UserID.Visible = true;
UserName.Visible = true;
PassWord.Visible = true;
PWD.Visible = true;
PWDFRIM.Visible = true;
PasswordFirm.Visible = true;
Sex.Visible = true;
Man.Visible = true;
Women.Visible = true;
Job.Visible = true;
vacation.Visible = true;
Add.Visible = true;
Exit.Visible = true;
}
#endregion
private void Add_Click_1(object sender, EventArgs e)
{
ShowAll();
int sex;
sex = 0;
if (this.Women.Checked == true)
{
sex = 1;
}
string ConStr = @"DATA SOURCE=localhost/ORCL;User ID=guohongwei;PASSWORD=123456;PERSIST SECURITY INFO=True;";
string sql = @"insert into BASEINF(ID,CODE,PWD,GENDER,JOB) values('" + 1 + "','" + this.UserID.Text.Trim() + "','" + this.PWD.Text.Trim() + "'," + sex + ",'" + this.vacation.Text.Trim() + "')";
//string sql = @"Insert into BASEINF(ID,PWD,GENDER,JOB) select '" + this.UserID.Text.Trim() + "','" + this.PWD.Text.Trim() + "'," + sex + ",'" + this.vacation.Text.Trim() + "' from BASEINF";
string sql2 = @"select * from BASEINF";
if (UserID.Text != null || PWD.Text != null || PWDFRIM.Text!= null || (Man.Checked!=false&&Women.Checked!=false||vacation.Text != null))
{
if (PWD.Text.Length < 6)
{
MessageBox.Show("密码长度最少为6位!");
PWD.Clear();
PWD.Focus();
PWDFRIM.Clear();
}
else
if (PWD.Text == PWDFRIM.Text)
{
DataTable dt = new DataTable();
//this.dataGridView1.DataSource = null;
OracleConnection Conn = new OracleConnection(ConStr);
Conn.Open();
OracleCommand cmd = new OracleCommand(sql, Conn);
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
OracleCommand cmd2 = new OracleCommand(sql2, Conn);
OracleDataAdapter adapt = new OracleDataAdapter(cmd2);
adapt.Fill(dt);
this.dataGridView1.DataSource = dt;
MessageBox.Show("注册成功!");
HideAdd();
}
else
{
MessageBox.Show("注册失败!");
UserID.Clear();
PWD.Clear();
PWDFRIM.Clear();
vacation.Clear();
}
}
else
{
MessageBox.Show("两次密码不一致!");
PWDFRIM.Clear();
PWDFRIM.Focus();
}
}
else
{
MessageBox.Show("数据不能为空!");
}
}
错误:
“System.Data.OracleClient.OracleException”类型的未经处理的异常在 System.Data.OracleClient.dll 中发生 其他信ORA-12514: TNS:listener does not currently know of service requested in connect descripto
错误是指在Conn.Open上的。