Connecting C# with Oracle 11g use SQL insert – select Tutorial 2

Video ready, click here to close ×


Connecting C# with Oracle 11g use SQL insert – select Tutorial 2

to download visual studio tools for oracle

http://www.oracle.com/technetwork/developer-tools/visual-studio/overview/index.html

the code used in the project

try
{
OracleConnection conn = new OracleConnection(“DATA SOURCE=DESKTOP-A5RDI03:1521/orcl;PERSIST SECURITY INFO=True;USER ID=SYSTEM; Password=123”);
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = “insert into ts (name,age) values(‘”+this.textBox1.Text+”‘,”+textBox2.Text+”)”;

conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show(“ok”);

viewdata();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

}

void viewdata() {
OracleConnection conn = new OracleConnection(“DATA SOURCE=DESKTOP-A5RDI03:1521/orcl;PERSIST SECURITY INFO=True;USER ID=SYSTEM; Password=123”);
OracleDataAdapter dr = new OracleDataAdapter(“select * from ts”, conn);

DataSet ds = new DataSet();
ds.Tables.Add(“ts”);
dr.Fill(ds, “ts”);

this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = “ts”;

}

source

2 comments

Leave a Reply

Your email address will not be published. Required fields are marked *