What's Here?
- Members: 340,078
- Replies: 920,283
- Topics: 154,906
- Snippets: 4,854
- Tutorials: 1,257
- Total Online: 4,784
- Members: 126
- Guests: 4,658
|
Welcome to Dream.In.Code |
|
|
Become an Expert!
Join 340,078 Programmers for FREE! Get instant access to thousands  of experts, tutorials, code snippets, and more! There are 4,784 people online right now. Registration is fast and FREE... Join Now!
Chat LIVE With a Expert
|
Insert Date in SQLdatabase
Insert Date in SQLdatabase
help me plz
Rate Topic:
   

- New D.I.C Head
-
-
Group:
New Members
-
Posts:
4
-
Joined:
10-May 09
Dream Kudos: 0
Posted 11 May 2009 - 09:35 PM
ASP.Net
<%@ 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#
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.
-
Group:
Members
-
Posts:
155
-
Joined:
28-October 08
Dream Kudos: 0
Posted 11 May 2009 - 10:46 PM
ratneshsoni, on 11 May, 2009 - 09:35 PM, said:
ASP.Net
<%@ 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#
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.
SqlCommand insert= new SqlCommand("INSERT INTO student(EID,Name,Address,Date) VALUES('" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox3.Text + "', '" + TextBox4.Text + "')", db_connection);
insert.ExecuteNonQuery();

- New D.I.C Head
-
-
Group:
New Members
-
Posts:
4
-
Joined:
10-May 09
Dream Kudos: 0
Posted 12 May 2009 - 03:33 AM
newProgram, on 11 May, 2009 - 10:46 PM, said:
ratneshsoni, on 11 May, 2009 - 09:35 PM, said:
ASP.Net
<%@ 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#
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.
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...
-
Group:
Members
-
Posts:
155
-
Joined:
28-October 08
Dream Kudos: 0
Posted 12 May 2009 - 05:48 PM
ratneshsoni, on 12 May, 2009 - 03:33 AM, said:
newProgram, on 11 May, 2009 - 10:46 PM, said:
ratneshsoni, on 11 May, 2009 - 09:35 PM, said:
ASP.Net
<%@ 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#
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.
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
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.
Posted 15 May 2009 - 06:34 PM
What data type is the Date column in your database table?

- New D.I.C Head
-
-
Group:
New Members
-
Posts:
4
-
Joined:
10-May 09
Dream Kudos: 0
Posted 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
-
Group:
Members
-
Posts:
155
-
Joined:
28-October 08
Dream Kudos: 0
Posted 26 May 2009 - 11:05 PM
ratneshsoni, on 25 May, 2009 - 02:37 AM, said:
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.

- New D.I.C Head
-
-
Group:
New Members
-
Posts:
4
-
Joined:
10-May 09
Dream Kudos: 0
Posted 30 May 2009 - 09:53 PM
newProgram, on 26 May, 2009 - 11:05 PM, said:
ratneshsoni, on 25 May, 2009 - 02:37 AM, said:
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...
-
Group:
Members
-
Posts:
155
-
Joined:
28-October 08
Dream Kudos: 0
Posted 31 May 2009 - 09:13 PM
ratneshsoni, on 30 May, 2009 - 09:53 PM, said:
newProgram, on 26 May, 2009 - 11:05 PM, said:
ratneshsoni, on 25 May, 2009 - 02:37 AM, said:
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.
1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users
|
Be Social
Programming
Web Development
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|