I'm going to Insert values to two table in Oracle.When i insert the record to first table and i need to get the Id of that table and it needs to enter the Second table.
Using my query It insert the values to first table.
public bool AddNewNews(NEWS nws)
{
bool status = false;
try
{
DatabaseProviderFactory factory = new DatabaseProviderFactory();
Database db = factory.Create("CharikaConString");
con.Open();
string query = @"INSERT INTO NEWS_TBL(NewsID,NAME)
VALUES(newsid.nextval,:NAME)";
cmd = db.GetSqlStringCommand(query);
db.AddInParameter(cmd, "NAME", DbType.String, nws.NAME);
db.ExecuteNonQuery(cmd);
// In the below commented lines are,I tried to insert second table but not success.
// String query2 = "Select newsid.currval";
//string query2 = @"INSERT INTO DTL_TBL(DtlId,desc) VALUES (newsid.currval,nws.Desc)";
// cmd = db.GetSqlStringCommand(query);
//db.AddInParameter(cmd, "desc", DbType.String, nws.Desc);
// db.ExecuteNonQuery(cmd);
}
catch (Exception ex)
{
throw;
}
finally
{
con.Close();
}
return status;
}