小项目当中要使用C#来连接Oracle数据库来完成系统的操作, 参考了MSDN文档才把数据库连接起来了,并能够通过SQL语句来完成基本的操作。
  操作代码示例:
//从数据库中读出数据来与控件对象中获得的值进行匹配,完成简单的验证功能。证明能够从数据库读出对应的数据
private void buttonCheck_Click(object sender, EventArgs e)
{
OracleConnection connection = new OracleConnection();
connection.ConnectionString = "Data Source = ORCL;User ID=xiyoulele;Password=xiyoulele;Unicode=false;" + "Persist Security Info=False";
connection.Open();
OracleCommand myCommand = connection.CreateCommand();
myCommand.CommandText = "select * from users";
OracleDataReader datareader = myCommand.ExecuteReader();
datareader.Read();
OracleString oraclestringFirst = datareader.GetOracleString(0);
string firstStr = oraclestringFirst.ToString();
OracleString oraclestringSecond = datareader.GetOracleString(1);
string secondStr = oraclestringSecond.ToString();
if (firstStr == "admin" && secondStr == "888888")
{
MessageBox.Show("成功通过!");
}
else
{
MessageBox.Show("有问题!");
}
}
//向数据库中插入新的记录
private void buttonRegister_Click(object sender, EventArgs e)
{
OracleConnection orclConn = new OracleConnection();
orclConn.ConnectionString = "Data Source = ORCL; User ID = xiyoulele; Password = xiyoulele; Unicode = false;" + "Persist Security Info = False";
orclConn.Open();
OracleCommand orclCmd = orclConn.CreateCommand();
orclCmd.CommandText = "insert into users values('xiyoulele','55555555')";
orclCmd.ExecuteNonQuery();
orclConn.Close();
MessageBox.Show("注册成功!");
}
  说明:这段代码是从测试的Demo当中的点击连接事件当中代码当中拿出来的。。。