thenndral 0 Newbie Poster

Hi,

I'm using c#2008
DB - oracle11G
Below I coded for Single table - [Insert/update/delete] for Single datagridview.

private void Form1_Load(object sender, EventArgs e)
        {

	    connectionString = "User Id=tommy;Password=hellotommy;Data Source=oracle_tommy";
            cn = new OracleConnection(connectionString);
            
	    cmd = new OracleCommand("Select id, name, dept, address, active from employee", cn);
            adapter = new OracleDataAdapter(cmd);
            cmb = new OracleCommandBuilder(adapter);

            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.MultiSelect = false;

            ds = new DataSet();
            adapter.Fill(ds);

            dataGridView1.DataSource = ds.Tables[0];
            empTbl = ds.Tables[0];
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            connectionString = "User Id=tom;Password=pwd4tom;Data Source=remote_oracle";
            cn = new OracleConnection(connectionString);

            OracleCommand command;
            string insertQuery = @"insert into employee(id, name, dept, address, active) Values 
                              (@id, @name, @dept, @address, @active;)";
            
            //MessageBox.Show(insertQuery);

            command = new OracleCommand(insertQuery, cn);
            command.Parameters.Add("@id", OracleDbType.Varchar2, 10, "id");
            command.Parameters.Add("@name", OracleDbType.Varchar2, 100, "name");
            command.Parameters.Add("@dept", OracleDbType.Varchar2, 100, "dept");
            command.Parameters.Add("@address", OracleDbType.Varchar2, 100, "address");
            command.Parameters.Add("@active", OracleDbType.Varchar2, 10, "active");
            adapter.InsertCommand = command;

          
            string updateQuery = @"update employee set name=@name, dept=@dept, address=@address, 
                        active=@active where id=@id;";
            command = new OracleCommand(updateQuery, cn);
            command.Parameters.Add("@name", OracleDbType.Varchar2, 50, "name");
            command.Parameters.Add("@dept", OracleDbType.Varchar2, 3, "dept");
            command.Parameters.Add("@address", OracleDbType.Varchar2, 50, "address");
            command.Parameters.Add("@active", OracleDbType.Varchar2, 10, "active");
            OracleParameter param1 = command.Parameters.Add("@id", OracleDbType.Int16, 5, "id");
            param1.SourceVersion = DataRowVersion.Original;
            adapter.UpdateCommand = command;

            string deleteQuery = @"Delete employee where id=@id;";
            command = new OracleCommand(deleteQuery, cn);
            OracleParameter paramd1 = command.Parameters.Add("@id", OracleDbType.Int16, 5, "id");
            paramd1.SourceVersion = DataRowVersion.Original;
            adapter.DeleteCommand = command;

            OracleCommandBuilder builder = new OracleCommandBuilder(adapter);
            adapter.UpdateCommand = builder.GetUpdateCommand();
            adapter.InsertCommand = builder.GetInsertCommand();
            adapter.DeleteCommand = builder.GetDeleteCommand();

            adapter.Update(empTbl); 
            
        }

I don't know how to show/insert/update/delete 2 or more tables in a single datagridview.
I can write code join sql query and show the two or more data in a single datagirdview.
But how to insert/update/delete?

can you give me some suggestion.

thanks in advance,
thenndral.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.