Click here to Skip to main content
15,909,896 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hello,

I have a Oracle connection and I want to delete a record from the database when I check a listview item.
When I push delete, I want to delete all items from the listview if they are duplicated and also from the database.
How can I do that?
Posted
Updated 25-May-10 6:19am
v7

Hi,

I found some solution related to your query... Below code is for C# to deleted record from oracle DB.

C#

C#
// Step 6
// Cleanup DeptTab table data
OracleCommand cmd2 = new OracleCommand("",connection);

// Delete all the rows from the DeptTab table
cmd2.CommandText = "DELETE depttab WHERE deptno = :1";

// Bind with an array of 3 items
cmd2.ArrayBindCount = 3;

OracleParameter param1 = new OracleParameter();
param1.OracleDbType = OracleDbType.Int32;
param1.Value = myArrayDeptNo;
cmd2.Parameters.Add(param1);

// Execute the delete statement through command
try

{
	cmd2.ExecuteNonQuery();
	Console.WriteLine("Cleaned DeptTab table data");
}
catch (Exception e)
{
	Console.WriteLine("Cleanup Failed:{0}" ,e.Message);}
finally
{
	// Dispose the OracleCommand objects
	cmd1.Dispose();
	cmd2.Dispose();

	// Close and Dispose the OracleConnection object
	connection.Close();
	connection.Dispose();
}


Hope this will help you.

Regards,

Nilesh Shah.
 
Share this answer
 
v2
Comments
Ankur\m/ 24-May-10 6:09am    
Please enclose code snippet within PRE tags (code block).
//new connection
OracleCommand cmd2 = new OracleCommand("",connection);

// Delete rows from the table
cmd2.CommandText = "DELETE depttab WHERE deptno = :1";

// Bind with an array of 3 items
cmd2.ArrayBindCount = 3;

OracleParameter param1 = new OracleParameter();
param1.OracleDbType = OracleDbType.Int32;
param1.Value = myArrayDeptNo;
cmd2.Parameters.Add(param1);


try

{
cmd2.ExecuteNonQuery();
Console.WriteLine("delete table data");
}
catch (Exception e)
{
Console.WriteLine("delete item Failed:{0}" ,e.Message);}
finally
{
cmd2.Dispose();

connection.Close();
connection.Dispose();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900