Posts tagged: oracle provider for .net

Oct 08 2009

Insert data into asp.net using Oracle Provider msdaora.1

In Oracle
I am going to Create a table in Oracle using database name is dbName

Database name is dbName

Create a table name tblSales with three fields

create table TBLSALES
(
SALESCODE NUMBER not null,
ITEMS     CHAR(32) not null,
SALESDATE DATE not null
)

In Visual Studio

I am going to explain the steps to insert the data into oracle using asp.net application.

Step1: Open VS2005 or 2008 -> New -> website -> choose Asp.net Web     site -> Ok

Step2: Open web.config file to write connection string.

<appSettings>
<add key=”ConnectionString” value=”Provider=msdaora.1;Data Source=dbName;User;Password=aaa;Persist Security Info=True;” />
</appSettings>

step3: In Default.aspx page, Drag three textbox,Button and calender control by clicking calender control date, the date will be displayed in txtDate(its id name of TextBox3)

oracle form

oracle form

give textbox1 ID is txtSalescode
textBox2 ID is txtItems
textBox3 Id is txtDate
Button ID is btnSubmitSales
Step4: In Default.aspx.cs write below code.

add namespace using System.Data.OleDb;

Sample Code in Default.aspx.cs

using System.Data.OleDB;

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
txtDate.Text = Calendar1.SelectedDate.ToShortDateString();
}

protected void btnSubmitSales_Click(object sender, EventArgs e)
{

OleDbConnection objConn = new OleDbConnection(ConfigurationManager.AppSettings["ConnectionString"]);

string query = “insert into tblSales(Salescode,Items,SalesDate) values(?,?,?)”;

OleDbCommand objCmd = new OleDbCommand(query, objConn);

objCmd.CommandType = CommandType.Text;

objCmd.Parameters.Add(”@SalesCode”, OleDbType.BigInt).Value = long.Parse(txtSalescode.Text);

objCmd.Parameters.Add(”@Items”, OleDbType.VarChar).Value = txtItems.Text;

objCmd.Parameters.Add(”@SalesDate”, OleDbType.Date).Value = txtDate.Text;

objConn.Open();

objCmd.ExecuteNonQuery();

objConn.Close();

}

Alibi3col theme by Themocracy