What's Here?
Members: 307,175
Replies: 841,966
Topics: 140,718
Snippets: 4,468
Tutorials: 1,165
Total Online: 1,580
Members: 95
Guests: 1,485
Loading. Please Wait...
Insert Date in SQLdatabase
Insert Date in SQLdatabase, help me plz
ratneshsoni
11 May, 2009 - 09:35 PM
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.
Replies(1 - 8)
newProgram
RE: Insert Date In SQLdatabase 11 May, 2009 - 10:46 PM
D.I.C Head
Joined: 28 Oct, 2008
Posts: 152
Thanked: 4 times
My Contributions
QUOTE(ratneshsoni @ 11 May, 2009 - 09:35 PM)
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.
Why not try this one. On your Button1_Click1 event when you are inserting the data.
CODE
SqlCommand insert= new SqlCommand("INSERT INTO student(EID,Name,Address,Date) VALUES('" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox3.Text + "', '" + TextBox4.Text + "')", db_connection); insert.ExecuteNonQuery();
ratneshsoni
RE: Insert Date In SQLdatabase 12 May, 2009 - 03:33 AM
New D.I.C Head
Joined: 10 May, 2009
Posts: 4
QUOTE(newProgram @ 11 May, 2009 - 10:46 PM)
QUOTE(ratneshsoni @ 11 May, 2009 - 09:35 PM)
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.
Why not try this one. On your Button1_Click1 event when you are inserting the data.
CODE
SqlCommand insert= new SqlCommand("INSERT INTO student(EID,Name,Address,Date) VALUES('" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox3.Text + "', '" + TextBox4.Text + "')", db_connection); insert.ExecuteNonQuery();
it is still not working plz make me solution for this...
newProgram
RE: Insert Date In SQLdatabase 12 May, 2009 - 05:48 PM
D.I.C Head
Joined: 28 Oct, 2008
Posts: 152
Thanked: 4 times
My Contributions
QUOTE(ratneshsoni @ 12 May, 2009 - 03:33 AM)
QUOTE(newProgram @ 11 May, 2009 - 10:46 PM)
QUOTE(ratneshsoni @ 11 May, 2009 - 09:35 PM)
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.
Why not try this one. On your Button1_Click1 event when you are inserting the data.
CODE
SqlCommand insert= new SqlCommand("INSERT INTO student(EID,Name,Address,Date) VALUES('" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox3.Text + "', '" + TextBox4.Text + "')", db_connection); insert.ExecuteNonQuery();
it is still not working plz make me solution for this...
Are you recieving an error? What type of error is it? Put your connection string below the namespace of your program, so that the variable you declare will be public. At the Button1_Click1 put this codes
CODE
protected void Button1_Click1(object sender, EventArgs e) { connection.Open(); SqlCommand insert = null; try { insert= new SqlCommand("INSERT INTO student(EID,Name,Address,Date) VALUES('" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox3.Text + "', '" + TextBox4.Text + "')", connection); insert.ExecuteNonQuery(); } catch { } finally { If(insert != null) { insert.Dispose(); insert = null; } connection.Close(); }
Give this a try and tell me if you encounter an error. Goodluck.
ratneshsoni
RE: Insert Date In SQLdatabase 25 May, 2009 - 02:37 AM
New D.I.C Head
Joined: 10 May, 2009
Posts: 4
QUOTE
hello...problem of inserting date is been solved but the another problem is that when i click on calender month change button it automatically postback.which I dont want.I check all properties of calender control but i cant find solution.plz help me to solve this problem
newProgram
RE: Insert Date In SQLdatabase 26 May, 2009 - 11:05 PM
D.I.C Head
Joined: 28 Oct, 2008
Posts: 152
Thanked: 4 times
My Contributions
QUOTE(ratneshsoni @ 25 May, 2009 - 02:37 AM)
QUOTE
hello...problem of inserting date is been solved but the another problem is that when i click on calender month change button it automatically postback.which I dont want.I check all properties of calender control but i cant find solution.plz help me to solve this problem
On the calendar properties set AutoPostBack to false.
ratneshsoni
RE: Insert Date In SQLdatabase 30 May, 2009 - 09:53 PM
New D.I.C Head
Joined: 10 May, 2009
Posts: 4
QUOTE(newProgram @ 26 May, 2009 - 11:05 PM)
QUOTE(ratneshsoni @ 25 May, 2009 - 02:37 AM)
QUOTE
hello...problem of inserting date is been solved but the another problem is that when i click on calender month change button it automatically postback.which I dont want.I check all properties of calender control but i cant find solution.plz help me to solve this problem
On the calendar properties set AutoPostBack to false.
QUOTE
can anybody help that when i select item for list of dropdown control its related table open in gridview. like when i select "jodhpur" from dropdown list its related table from sql database open.or when i select "jaipur" then its tables and so on... plz help me in this task...
newProgram
RE: Insert Date In SQLdatabase 31 May, 2009 - 09:13 PM
D.I.C Head
Joined: 28 Oct, 2008
Posts: 152
Thanked: 4 times
My Contributions
QUOTE(ratneshsoni @ 30 May, 2009 - 09:53 PM)
QUOTE(newProgram @ 26 May, 2009 - 11:05 PM)
QUOTE(ratneshsoni @ 25 May, 2009 - 02:37 AM)
QUOTE
hello...problem of inserting date is been solved but the another problem is that when i click on calender month change button it automatically postback.which I dont want.I check all properties of calender control but i cant find solution.plz help me to solve this problem
On the calendar properties set AutoPostBack to false.
QUOTE
can anybody help that when i select item for list of dropdown control its related table open in gridview. like when i select "jodhpur" from dropdown list its related table from sql database open.or when i select "jaipur" then its tables and so on... plz help me in this task...
Yes, all you have to do is to query the data on the table and bind the dataset on your datagrid. Make sure your DropDown's AutoPostBack is true.