ASP.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a ASP.NET Expert!

Join 308,429 ASP.NET Programmers for FREE! Get instant access to thousands of ASP.NET experts, tutorials, code snippets, and more! There are 3,234 people online right now. Registration is fast and FREE... Join Now!




Insert Date in SQLdatabase

 

Insert Date in SQLdatabase, help me plz

ratneshsoni

11 May, 2009 - 09:35 PM
Post #1

New D.I.C Head
*

Joined: 10 May, 2009
Posts: 4

ASP.Net
CODE

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Label ID="Label1" runat="server" Text=" "></asp:Label>
    <br /><br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>    
    <asp:Button ID="Button1" runat="server" Text="Save"/>
     <br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
     <br />
    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
   <br />
    
        <asp:TextBox id="TextBox4" runat="server"></asp:TextBox>
  <INPUT type="button" value="..." onclick="OnClick()" id="Button1"><br>              
  <asp:DropDownList ID="DropDownList1" runat="server" Onclick="OnClick()" ></asp:DropDownList>

  <div id="divCalendar" style="DISPLAY: none; POSITION: absolute; z-index: 101;">
  <asp:Calendar id="Calendar1" runat="server" BorderWidth="2px"
                BackColor="White" Width="200px"
    ForeColor="Black" Height="180px" Font-Size="8pt"
                      Font-Names="Verdana" BorderColor="#999999"
    BorderStyle="Outset" DayNameFormat="FirstLetter" CellPadding="4" OnSelectionChanged="Calendar1_SelectionChanged">
    <TodayDayStyle ForeColor="Black" BackColor="#CCCCCC">
      </TodayDayStyle>
    <SelectorStyle BackColor="#CCCCCC"></SelectorStyle>
    <NextPrevStyle VerticalAlign="Bottom"></NextPrevStyle>
    <DayHeaderStyle Font-Size="7pt" Font-Bold="True"
                    BackColor="#CCCCCC"></DayHeaderStyle>
    <SelectedDayStyle Font-Bold="True" ForeColor="White"
                      BackColor="#666666"></SelectedDayStyle>
    <TitleStyle Font-Bold="True" BorderColor="Black"
                BackColor="#999999"></TitleStyle>
    <WeekendDayStyle BackColor="#FFFFCC"></WeekendDayStyle>
    <OtherMonthDayStyle ForeColor="#808080"></OtherMonthDayStyle>
  </asp:Calendar>
  </div>
<script language="javascript">
function OnClick()
{
  if( divCalendar.style.display == "none")
    divCalendar.style.display = "";
  else
    divCalendar.style.display = "none";
}
</script>
    </form>
</body>
</html>



C#
CODE

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        TextBox4.Text = Calendar1.SelectedDate.ToShortDateString();
        
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        ConnectionStringSettings insertdata = ConfigurationManager.ConnectionStrings["InsertDataConnectionString"];
        SqlConnection connection = new SqlConnection(insertdata.ConnectionString);

        connection.ConnectionString = "Data Source=SEEMA-957805D5D;Initial Catalog=InsertData;Integrated Security=True;Pooling=False";
        SqlCommand cmd = (SqlCommand)connection.CreateCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "SELECT * FROM student";
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet("insertd");
        da.Fill(ds, "Student");
        connection.Open();

        cmd.Parameters.Add("@EID", TextBox1.Text);
        cmd.Parameters.Add("@Name", TextBox2.Text);
        cmd.Parameters.Add("@Address", TextBox3.Text);
        cmd.Parameters.Add("@Date", TextBox4.Text);

        cmd.CommandText = "INSERT INTO student(EID,Name,Address,Date) VALUES (@EID,@Name,@Address,@Date)";
        cmd.ExecuteNonQuery();
        Label1.Text = "Insertion Sussesful";
        da.Update(ds, "Student");
        connection.Close();
    }


Value not go to database when i take calender to store the date in database.Before this it working.It not shows any error when I click on button to save Data.
plz help me.

User is offlineProfile CardPM
+Quote Post



Fast ReplyReply to this topicStart new topic

Time is now: 11/24/09 01:49PM

Live ASP.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

ASP.NET Tutorials

Reference Sheets

ASP.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month