string dateTime = DateTime.Now.ToString("yyyy-MM-dd h:mm tt");
DateTime dt = DateTime.Parse(dateTime);
Thứ Tư, 30 tháng 7, 2014
chuyển từ chuỗi sang datetime
Thứ Ba, 29 tháng 7, 2014
Lấy các ngày trong tuần sử dụng biến DateTime C#
using System; class Program { static void Main() { // Get currrent day of week. DayOfWeek today = DateTime.Today.DayOfWeek; Console.WriteLine("Today is {0}", today); // Test current day of week. if (today == DayOfWeek.Monday) { Console.WriteLine("DO WORK"); } // Demonstrate all DayOfWeek values. Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, {6}", DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday); } } Output Today is Monday DO WORK Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
Thứ Bảy, 26 tháng 7, 2014
Thêm dữ liệu quan hệ giữa hai bảng trong C# - Add Relations
In a DataSet with multiple DataTable objects, you can use DataRelation
objects to relate one table to another, to navigate through the tables,
and to return child or parent rows from a related table.
The arguments required to create a DataRelation are a name for the DataRelation being created, and an array of one or more DataColumn references to the columns that serve as the parent and child columns in the relationship. After you have created a DataRelation, you can use it to navigate between tables and to retrieve values.
Adding a DataRelation to a DataSet adds, by default, a UniqueConstraint to the parent table and a ForeignKeyConstraint to the child table. For more information about these default constraints, see DataTable Constraints.
The following code example creates a DataRelation using two DataTable objects in a DataSet. Each DataTable contains a column named CustID, which serves as a link between the two DataTable objects. The example adds a single DataRelation to the Relations collection of the DataSet. The first argument in the example specifies the name of the DataRelation being created. The second argument sets the parent DataColumn and the third argument sets the child DataColumn.
The arguments required to create a DataRelation are a name for the DataRelation being created, and an array of one or more DataColumn references to the columns that serve as the parent and child columns in the relationship. After you have created a DataRelation, you can use it to navigate between tables and to retrieve values.
Adding a DataRelation to a DataSet adds, by default, a UniqueConstraint to the parent table and a ForeignKeyConstraint to the child table. For more information about these default constraints, see DataTable Constraints.
The following code example creates a DataRelation using two DataTable objects in a DataSet. Each DataTable contains a column named CustID, which serves as a link between the two DataTable objects. The example adds a single DataRelation to the Relations collection of the DataSet. The first argument in the example specifies the name of the DataRelation being created. The second argument sets the parent DataColumn and the third argument sets the child DataColumn.
customerOrders.Relations.Add("CustOrders", customerOrders.Tables["Customers"].Columns["CustID"], customerOrders.Tables["Orders"].Columns["CustID"]);
Tính toán chênh lệch giờ - phút - giây
DateTime startTime = DateTime.Now;
DateTime endTime = DateTime.Now.AddSeconds( 75 );
TimeSpan span = endTime.Subtract ( startTime );
Console.WriteLine( "Time Difference (seconds): " + span.Seconds );
Console.WriteLine( "Time Difference (minutes): " + span.Minutes );
Console.WriteLine( "Time Difference (hours): " + span.Hours );
Console.WriteLine( "Time Difference (days): " + span.Days );
Thứ Bảy, 19 tháng 7, 2014
Cách mở cổng trong Win7
1) Go to Start -> Control Panel -> System and Security -> Windows Firewall.
2) On the left, click "Advanced settings".
3) On the left again, click "Inbound Rules" (if the the port is supposed to be outbound, click "Outbound Rules").
4) Go though the wizard.
2) On the left, click "Advanced settings".
3) On the left again, click "Inbound Rules" (if the the port is supposed to be outbound, click "Outbound Rules").
4) Go though the wizard.
Thứ Tư, 16 tháng 7, 2014
Cách hhai báo và sử dụng biến Dictionary với drop down list trong C#
1. Tạo một trang aspx -
kéo control dropdownlist vào trang
đặt ID của control là ddl
2. Nhấn phím F7 vào code behind,
trong thủ tục page_load thêm đoạn code này vào:
//int là kiểu giá trị cho key, string là kiểu giá trị áp dụng cho valúe
Dictionary<int, string> objItems = new
Dictionary<int, string>
();
objItems
.Add(1, "Item 1");
objItems
.Add(2, "Item 2");
objItems
.Add(3, "Item 3");
objItems
.Add(4, "Item 4"); ddl.DataSource =
; ddl.DataTextField = "Value"; ddl.DataValueField = "Key"; ddl.DataBind();
objItems
Thứ Hai, 14 tháng 7, 2014
Lỗi xảy ra khi đếm sql
Arithmetic overflow error converting expression to data type int.
The Explanation: The upper bounds of an int is a little over two billion: 2,147,483,647. The count() function always returns an int.
The Solution: Use count_big() instead, as it always returns a bigint data type, which has an upper bound of 9,223,372,036,854,775,807. “select count_big(1) from MY_HUGE_TBL”
The Explanation: The upper bounds of an int is a little over two billion: 2,147,483,647. The count() function always returns an int.
The Solution: Use count_big() instead, as it always returns a bigint data type, which has an upper bound of 9,223,372,036,854,775,807. “select count_big(1) from MY_HUGE_TBL”
Chủ Nhật, 6 tháng 7, 2014
Tạo một mảng dùng nhiều phần tử để tách mảng sử dụng hàm Split trong C#
var arraySplit={" ",",",";"};
var Source="text,tex2;text3 text4";
var NewArray = Source.Split(mang, StringSplitOptions.None);
var Source="text,tex2;text3 text4";
var NewArray = Source.Split(mang, StringSplitOptions.None);
Thứ Tư, 2 tháng 7, 2014
Câu lệnh lấy các phần tử trong một mảng linq C#
// khai một mảng gồm 7 phần tử có giá trị tương ứng từ 0 tới 6 int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
var myVariable = (from l in numbers // lấy các phần tử trong numbers order by l decending// và xắp xếp theo thứ tự giảm dần select l).take(3);// lấy 3 phần tử đầu tiên của mảng.
Thứ Ba, 1 tháng 7, 2014
Điều chỉnh style - css cho thẻ a hay hyperlink trong html
Cách định dạng CSS thuộc tính cho thẻ a hay link trong html (vd. màu sắc, dạng chữ (font), màu nền...) ở những trạng thái khác nhau của thẻ a hay link
thẻ a có 4 trạng thái thể hiện cho người dùng trên trang web:
- a:link - trạng thái thể hiện cho thẻ khi người dùng chưa kích vào link.
- a:visited - trạng thái thể hiện trạng thái người dùng đã kích vào link rồi
- a:hover - trạng thái thể hiện của link khi người dùng di chuột vào
- a:active - thể hiện link này khi người dùng kích vào link
a:link {
color: #FF0000;
}
/* 2. link đã xem rồi */
a:visited {
color: #00FF00;
}
/* 3. di chuột nên link */
a:hover {
color: #FF00FF;
}
/* 4. chọn link */
a:active {
color: #0000FF;
}
định dạng cho các trạng thái của link buộc phải theo thứ tự từ trên xuống dưới như ở trên
Đăng ký:
Bài đăng (Atom)