having difficulty with where to write the code

asp.net(c#) with oracle as database

Page 1 of 1

4 Replies - 2212 Views - Last Post: 06 July 2007 - 02:05 PM Rate Topic: -----

#1 geeteshss  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-June 07

having difficulty with where to write the code

Post icon  Posted 22 June 2007 - 03:33 AM

i have got a table in the oracle database in which i have to insert the data from my web form .i am sending the screen shots of all these
also i would like to know whether i have to use a oracle connection or oledb connection

i got many forums but i am confused actually it would have been a great help if anyone could explain me step by step

namespace WebApplication1
{
/// <summary>
/// Summary description for busarea.
/// </summary>
public class busarea : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.HyperLink HyperLink2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbCommand oleDbCommand1;
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand();
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
//
// oleDbConnection1
//
this.oleDbConnection1.InfoMessage += new System.Data.OleDb.OleDbInfoMessageEventHandler(this.oleDbConnection1_InfoMessage);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
string str = ConfigurationManager.appsettings["ConnectionString"].ToString();

OleDbConnection oracleConn = new OleDbConnection();

oracleConn.ConnectionString=str;

con.open();

OleDbCommand cmd = new OleDbCommand("Write your insert statement here like INSERT INTO TABLENAME VALUES (“YOUR VALUES", con);

OleDbDataReader dr = cmd.ExecuteReader();


}

private void Button3_Click(object sender, System.EventArgs e)
{

}



}
}

Attached File(s)

  • Attached File  p1.doc (92.5K)
    Number of downloads: 129
  • Attached File  p2.doc (84K)
    Number of downloads: 134

This post has been edited by geeteshss: 22 June 2007 - 03:35 AM


Is This A Good Question/Topic? 0
  • +

Replies To: having difficulty with where to write the code

#2 max302  Icon User is offline

  • Proud supporter of the lulz
  • member icon

Reputation: 2
  • View blog
  • Posts: 1,281
  • Joined: 05-March 06

Re: having difficulty with where to write the code

Posted 22 June 2007 - 07:18 AM

Code tags please?
Was This Post Helpful? 0
  • +
  • -

#3 geeteshss  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-June 07

Re: having difficulty with where to write the code

Posted 27 June 2007 - 11:45 PM

View Postmax302, on 22 Jun, 2007 - 07:18 AM, said:

Code tags please?

Hi max i didnt get u.
Was This Post Helpful? 0
  • +
  • -

#4 roadfury  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 52
  • Joined: 05-February 07

Re: having difficulty with where to write the code

Posted 06 July 2007 - 01:53 PM

It would be better to use the Oracle provider. Here's some code I've used before. I've put comments above each line.

 private void Button1_Click(object sender, System.EventArgs e)
{
//Retrieve the connection info.
//Should be in the form of: "User ID=USERID;Password=PASS;Data Source=SERVER;"
string str = ConfigurationManager.appsettings["ConnectionString"].ToString();

//Create an Oracle Connection object and link it to the Oracle server
System.Data.OracleClient.OracleConnection oracleConn = new System.Data.OracleClient.OracleConnection(str);

//Create an Oracle Command object for executing queries
System.Data.OracleClient.OracleCommand cmd = new System.Data.OracleClient.OracleCommand;

//Tell the Oracle Command object which connection to use
cmd.Connection = oracleConn;
//Open that connection to the server
cmd.Connection.Open();
//Specify the SQL code/query to execute. In this case we're issuing an INSERT statement.
//I'm assuming that area_code is numeric in the database, and area_desc is a string.
cmd.CommandText = "INSERT INTO CMRS_BUSINESSAREA_MASTER (CBM_BUSAREA_CODE, CBM_BUSAREA_DESC) VALUES (" + TextBox1.Text + ",'" + TextBox2.Text + "')";
//Execute the code/query. Since we're doing an INSERT, there are no records being returned, so use ExecuteNonQuery()
cmd.ExecuteNonQuery();
//Close the connection after we're finished with it
cmd.Connection.Close();


}



Also, this should have been posted to the C# forum. Please be more aware in the future.
Was This Post Helpful? 0
  • +
  • -

#5 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1876
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: having difficulty with where to write the code

Posted 06 July 2007 - 02:05 PM

Thread Moved.


Please use [code] tags (just like the gigantic text in the box you typed your post in told you to do)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1