nirjharini pradhan

nirjharini pradhan

  • NA
  • 94
  • 22.5k

conversion of asp.net Date to oracle date.

Feb 11 2016 12:52 AM
i m trying to insert the date from my textbox to oracle table.But it showing error invalid month please check my code...
 
jscode:----
 
<script>
$(function () {
$("#TextBox2").datepicker();
});
aspx:------
 
 
<div>
Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<br />
Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<br />
</div>
 
 
aspx.cs:---------------
 
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
public partial class TestDate : System.Web.UI.Page
{
OracleConnection cn = null;
protected void Page_Load(object sender, EventArgs e)
{
cn = new OracleConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
}
protected void Button1_Click(object sender, EventArgs e)
{
string query = "insert into DateDemo(NAME,TODAY)values('"+TextBox1.Text+"',"+DateTime.ParseExact(TextBox2.Text,"dd/mon/yyyy",null)+")";
OracleCommand cmd = new OracleCommand(query,cn);
if (cn.State != ConnectionState.Open)
cn.Open();
int affect = cmd.ExecuteNonQuery();
if (affect > 0)
Response.Write("success");
cn.Close();
}
}
 Thanks In Advance 
 
 
 

Answers (17)