|
 |
|
แปลง Label วันที่ลงฐานข้อมูลแต่ใน sql เป็น yyyy-MM-dd แต่ label เป็น dd-MM-yyyy แก้ยังไงครับ |
|
 |
|
|
 |
 |
|
แปลงให้ถูก Format ก่อนการ Insert ครับ อาจจะใช้การตัด แล้วให้รวม String ให้อยู่ใน Format ว่า YYYY-MM-DD ครับ
|
 |
 |
 |
 |
Date :
2013-03-09 15:33:00 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
protected void Page_Load(object sender, EventArgs e)
{
conn = new SqlConnection(strsql);
conn.Open();
Thread.CurrentThread.CurrentCulture = new CultureInfo("th-TH") ;
lblgetdate.Text = DateTime.Today.ToString("dd/MM/yyyy");
}
protected void ddldegree_SelectedIndexChanged(object sender, EventArgs e)
{
switch (ddlgraduate.Text)
{
case "ปริญญา": blreturndate.Text = DateTime.Now.AddDays(7).ToString("dd/MM/yyyy"); ; break;
case "บัณฑิตวิทยาลัย": blreturndate.Text = DateTime.Now.AddDays(14).ToString("dd/MM/yyyy"); ; break;
}
protected void Button3_Click(object sender, EventArgs e)
{
strsql = "insert into book(stuid,firstname,lastname,graduate,faculty,major,phone,isbn,book,startDate,endDate)";
strsql += "values('" + lblstuid.Text + "',";
strsql += "'" + lblfirstname.Text + "',";
strsql += "'" + lbllastname.Text + "',";
strsql += "'" + ddlgraduate.Text + "',";
strsql += "'" + lblfaculty.Text + "',";
strsql+="'"+lblmajor.Text+"',";
strsql+="'"+lblphone.Text+"',";
strsql += "'" + lblisbn.Text + "',";
strsql += "'" + lblbook.Text+ "',";
strsql += "'" + lblgetdate.Text +"',";
strsql += "'" + blreturndate.Text + "')";
}
สรูปจาก code แก้ตรง
protected void ddldegree_SelectedIndexChanged(object sender, EventArgs e)
{
switch (ddlgraduate.Text)
{
case "ปริญญา": blreturndate.Text = DateTime.Now.AddDays(7).ToString("dd/MM/yyyy"); ; break;
case "บัณฑิตวิทยาลัย": blreturndate.Text = DateTime.Now.AddDays(14).ToString("dd/MM/yyyy"); ; break;
}
เพระตอนนี้ label.Text ผมเป็น dd/MM/YYYY ให้แก้ตรงนี้หรือปล่าวครับให้เป็น yyyy/MM/dd ก่อนเข้า base
ถ้าแก้แล้วจะแสดงตอน ออก web เป็น dd/MM/YYYY ยังไงครับให้เป็น พศ เพราะเครื่องเป็น คศ ครับ
พอดีติดมาหลายวันแล้วครับขอบคุณมากครับ
|
 |
 |
 |
 |
Date :
2013-03-09 16:37:18 |
By :
clarity |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันบันทึกลงฐานข้อมูลไม่ได้เหรอครับ
blreturndate.Text = DateTime.Now.AddDays(7).ToString("dd/MM/yyyy");
//addday ผมไม่เคยใช้
ของผมทำแบบนี้ blreturndate.Text = Covert.Datetime.Now(DateTime.Now.ToString("s"); //s คือรูปแบบ มีหลายแบบนะ
|
 |
 |
 |
 |
Date :
2013-03-09 20:11:18 |
By :
ERO-TIC |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|