Hello all, i am new in this field and want some halp from all you.
Actually i have fetched the date only from system.But its having format like mm/dd/yy
but i want like that dd/mm/yy
following arethe .cs code:
insert code:
con.Open();
SqlCommand cmd = new SqlCommand("insert into contact_us (Name,Email_id,Mobile_no,Comments, entry_date ) values('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"', '"+System.DateTime.Today.ToShortDateString() +"' )",con);
SqlDataReader dr = cmd.ExecuteReader();
con.Close();
for fetching:
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select Name as'Name', Email_id as 'Email Id',Mobile_no as 'Mobile No',Comments as 'Comment', CONVERT(VARCHAR(20),entry_date,111) from contact_us", con);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();

Santhosh Kumar JayaramanPosted Jan 5, 2013, 4:55 AM
DateTime.Today.ToString("dd/MM/yy")
So your code will be
SqlCommand cmd = new SqlCommand("insert into contact_us (Name,Email_id,Mobile_no,Comments, entry_date ) values('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"', '"+System.DateTime.Today.ToString("dd/MM/yy") +"' )",con);
try and let us know
Mukesh KumarPosted Feb 21, 2013, 1:49 AM
Abhimanyu SinghPosted Feb 21, 2013, 12:48 AM
Good Morning!!
I have a request to you, i have posted a query but didnot get solution till now can you help me please.
If yes see this link: http://www.c-sharpcorner.com/Forums/Thread/201744/
And Also am giving you some clue of code from that query link....
Sorry!! I Cant Remove datasourceID from Designing/aspx Page because i already have explained in asked query (u can see above) that i have used the database property/sqldatasource1 to display the edit delete & select property in grid and this is running well also.
But only the problem is in i want some search button here with text boxes (see design page/attachment). while i coded on image button event initially it was throwing sqldatasource defination duplicacy, i tried every thing whis are instructed by you but its not working every time throwing some new error.
Please help me (any body here)
Sarch code on image button event:
Santhosh Kumar JayaramanPosted Jan 5, 2013, 6:36 AM
use this
dd/mmm/yy
you can see different formats and their output here
http://www.dotnetperls.com/datetime-format
regarding CAST in SQL server
Cast is used to convert from one datatype to another..
CAST and CONVERT are almost similar.
To know differnt types of dataformats for conversion, check this
there is a table with different dateformats.
http://msdn.microsoft.com/en-us/library/aa226054(v=sql.80).aspx
for each format there is a numeral, which we have to write during our conversion
Abhimanyu SinghPosted Jan 5, 2013, 6:27 AM
cud u tell me how to cast date nd time according to our convenience.
Like : mm/dd/yy(default) into dd/jan/yy or dd/MM/yy
i searched more answers but still didnot get it,
how to run this sql query:
CAST ( expression AS data_type [ (length ) ])
cud u explain plz if r u dere??
Abhimanyu SinghPosted Jan 5, 2013, 6:04 AM
Thax a lot
Santhosh Kumar JayaramanPosted Jan 5, 2013, 5:55 AM
Abhimanyu SinghPosted Jan 5, 2013, 5:55 AM
As per your instruction i have putted the same but
its throwing following error
No overload for method 'ToShortDateString' takes '1' arguments
venkata kumarPosted Jan 5, 2013, 4:58 AM
check this
SqlDataAdapter da = new SqlDataAdapter("select Name as'Name', Email_id as 'Email Id',Mobile_no as 'Mobile No',Comments as 'Comment', CONVERT(VARCHAR(20),entry_date,103) as entry_date from contact_us", con);
for fallowing u need set ur system date is mm/dd/yyyy
SqlCommand cmd = new SqlCommand("insert into contact_us (Name,Email_id,Mobile_no,Comments, entry_date ) values('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"', '"+System.DateTime.Today.ToShortDateString() +"' )",con);