Oracle Db Cresting table using C# query
i have 4 textboxes and 3 buttons in a webpage, in create button onclick event it should create a table in that emp id(number not null), name varchar, joindate (date) should be there, then in the button click of insert it should insert the data which is entered in 3 textboxes, and there is one more button search is there when we provide emp id in 4 th textbox it should display the regarding emp id details.
aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ora con.aspx.cs" Inherits="ora_con" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" >
</script>
</head>
<body>
<form id="form1" runat="server">
<div runat="server" id ="mydiv">
<br /> <asp:DropDownList runat="server" ID="ddlcon"
OnSelectedIndexChanged="ddlcons" AutoPostBack="true">
<asp:ListItem Value="0" Text="Select"></asp:ListItem>
<asp:ListItem Value="1" Text="Yes"></asp:ListItem>
<asp:ListItem Value="2" Text="No"></asp:ListItem>
</asp:DropDownList>
<br />
<table style="width:100%;">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnora" runat="server" Text="Create" onclick="btnora_Click" />
</td>
<td>
<asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="insert" />
</td>
<td>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="search"
style="height: 26px" />
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</td>
<td>
</td>
<td>
</td>
</tr>
</table> </div>
</form>
</body>
</html>
.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.OracleClient;
public partial class ora_con : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnora_Click(object sender, EventArgs e)
{
//try
//{
//use your own userid,password and datasorce
string Constring;
Constring = WebConfigurationManager.ConnectionStrings["QuickStarts Instance"].ConnectionString;
OracleConnection con = new OracleConnection(Constring);
con.Open();
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = "CREATE TABLE con(id varchar2(20),name varchar2(50), 'DATE (DATE)')"; // i dont know hw to create date datatype here
cmd.ExecuteNonQuery();
Response.Write("<script>alert('Successfully Created..');</script>");
//}
//catch (Exception)
//{
// Response.Write("<script>alert('Not Created..');</script>");
//}
}
protected void Button2_Click(object sender, EventArgs e)
{
{
string Constring, query;
Constring = WebConfigurationManager.ConnectionStrings["QuickStarts Instance"].ConnectionString;
OracleConnection con = new OracleConnection(Constring);
con.Open();
query = "SELECT name,id FROM con where id = '" + TextBox3.Text.Trim() + "'";
OracleCommand command = new OracleCommand(query, con);
OracleDataReader reader = command.ExecuteReader();
reader.Read();
TextBox2.Text = reader[0].ToString();
TextBox1.Text = reader[1].ToString();
reader.Close();
con.Close();
}
}
protected void ddlcons(object sender, EventArgs e)
{
if (ddlcon.SelectedValue.ToString() == "1")
{
TextBox1.Text = "";
TextBox2.Text = "";
// TextBox3.Text = "";
}
else
{
Console.WriteLine("No Changes");
}
}
protected void Button3_Click(object sender, EventArgs e)
{
{
string Constring;
Constring = WebConfigurationManager.ConnectionStrings["QuickStarts Instance"].ConnectionString;
OracleConnection con = new OracleConnection(Constring);
con.Open();
string str = "insert into con (id) values ('" + TextBox1.Text + "')";//,'" + TextBox2.Text + "')"; // i dont know how to insert date value
OracleCommand cmd = new OracleCommand(str, con);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("Inserted");
}
}
}