namespace WpfApplication2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private OracleConnection conn = new OracleConnection();
private OracleCommand cmd;
private OracleDataAdapter da;
private OracleCommandBuilder cb;
private DataSet1 dg;
private void connect_Click(object sender, RoutedEventArgs e)
{
conn.ConnectionString = "Data Source = orcl; User Id =HR;Password= HR;";
try
{
conn.Open();
string sql = "select * from inventory";
cmd = new OracleCommand(sql, conn);
cmd.CommandType = CommandType.Text;
da = new OracleDataAdapter(cmd);
cb = new OracleCommandBuilder(da);
dg = new DataSet1();
da.Fill(dg);
dataGrid.ItemsSource = dg.Tables[1].DefaultView;
}catch(OracleException ex)
{
switch (ex.Number)
{
case 1:
MessageBox.Show("Error attempting to insert duplicate data.");
break;
case 12560:
MessageBox.Show("The database is unavailable.");
break;
default:
MessageBox.Show("Database error: " + ex.Message.ToString());
break;
}
}catch(System.Windows.Markup.XamlParseException xe)
{
MessageBox.Show("oops");
}
catch (System.InvalidOperationException ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
// conn.Dispose();
}
}
private void update_Click(object sender, RoutedEventArgs e)
{
da.Update(dg.Tables[1]);
MessageBox.Show("updated...");
}