Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ขอถามเรื่อง Data Binding ใน VB.Net เวลากด save ข้อมูลDateDateTimePickerมันไม่ insert ลงใน Table ให้ครับ



 

ขอถามเรื่อง Data Binding ใน VB.Net เวลากด save ข้อมูลDateDateTimePickerมันไม่ insert ลงใน Table ให้ครับ

 



Topic : 119042



โพสกระทู้ ( 201 )
บทความ ( 0 )



สถานะออฟไลน์




จากที่ผมลองทำตาม วิดีโอ ในยูทูป
ขอถามเรื่อง Data Binding ใน VB.Net เวลากด save ข้อมูลของDateDateTimePicker ที่มัน Default วันที่ปัจจุบันไม่ insert ลงใน Table ให้แต่ถ้ามีการเลือกเป็นวันที่อื่น insert ได้ คือเหมือนมันมองค่า Default ของDateDateTimePicker เป็นค่าว่าง พอจะรูปวิธี setให้ค่าDefault เป็นเวลาปัจจุบันเลยไหมครับ

รูปอ้างอิง

พพพ

ผมใช้เป็น Dataset ลากวางๆทำตาม วิดีโอ ในยูทูปเลย

าาา



Tag : .NET, Ms SQL Server 2008, VB.NET









ประวัติการแก้ไข
2015-09-23 14:21:57
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-09-23 14:15:18 By : ์New_User View : 1909 Reply : 6
 

 

No. 1



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

DateDateTimePicker.Value = now

ใส่ไปซักที่ ก่อน save ก็ได้ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-09-23 14:24:58 By : lamaka.tor
 


 

No. 2



โพสกระทู้ ( 201 )
บทความ ( 0 )



สถานะออฟไลน์


พี่ lamaka.tor
Code (VB.NET)

โค้ต save อันนี้ครับ
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Validate()
        Me.MEMBERBindingSource1.AddNew()
        Me.TableAdapterManager1.UpdateAll(Me.Housing_FundDataSet1)
    End Sub


DateDateTimePicker.Value = now
จะใส่ในรูปแบบไหนครับผม

ที่ผมคิดคือหรือมันต้องไปกำหนดใน properties ของDateDateTimePicker เลยกำลังงง


ประวัติการแก้ไข
2015-09-23 14:40:42
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-09-23 14:38:42 By : ์New_User
 

 

No. 3



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

Code (VB.NET)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      DateDateTimePicker.Value = now

       Me.Validate()
       Me.MEMBERBindingSource1.AddNew()
       Me.TableAdapterManager1.UpdateAll(Me.Housing_FundDataSet1)
   End Sub



ผมไม่แนะนำให้เล่นกับ properties ครับ
ผมเป็นคนหนึ่งที่เวลาที่ต้องเขียนโปรแกรมใหม่แล้วมักจะจะงงกับการตั้งค่า
เลยตัดปัญหาคือ
เขียนเป็นโค้ดซะเลย

มีของมาฝากครับ(เผื่อสนใจ)
sdfgdgdfg


Code (C#)
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

#region _GridDateControl
public class GridDateControl : DataGridViewColumn
{

    public GridDateControl()
        : base(new CalendarCell())
    {
    }

    public override DataGridViewCell CellTemplate
    {
        get { return base.CellTemplate; }

        set
        {
            // Ensure that the cell used for the template is a CalendarCell.
            if ((value != null) && !value.GetType().IsAssignableFrom(typeof(CalendarCell)))
            {
                throw new InvalidCastException("Must be a CalendarCell");
            }
            base.CellTemplate = value;

        }
    }

}

public class CalendarCell : DataGridViewTextBoxCell
{

    public CalendarCell()
    {
        // Use the short date format.
      //  this.Style.Format = "dd MMMM yyyy  hh:mm:ss tt"; 

    }

    public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
    {
        // Set the value of the editing control to the current cell value.
        base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);

        CalendarEditingControl ctl = (CalendarEditingControl)DataGridView.EditingControl;
        if ((!object.ReferenceEquals(this.Value, DBNull.Value)))
        {
            if ((this.Value != null))
            {
                ctl.Value = (DateTime)this.Value;
            }
        }
    }

    public override Type EditType
    {
        // Return the type of the editing contol that CalendarCell uses.
        get { return typeof(CalendarEditingControl); }
    }

    public override Type ValueType
    {
        // Return the type of the value that CalendarCell contains.
        get { return typeof(DateTime); }
    }
}

class CalendarEditingControl : DateTimePicker, IDataGridViewEditingControl
{

    private DataGridView dataGridViewControl;
    private bool valueIsChanged = false;
    private int rowIndexNum;
    public CalendarEditingControl()
    {
        this.Format = DateTimePickerFormat.Short;
    }

    public object EditingControlFormattedValue
    {
        get { return this.Value.ToShortDateString(); }
        set
        {
            if (value is String)
            {
                this.Value = DateTime.Parse(Convert.ToString(value));
            }
        }
    }


    public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
    {

        return this.Value.ToShortDateString();

    }


    public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
    {
        this.Font = dataGridViewCellStyle.Font;
        this.CalendarForeColor = dataGridViewCellStyle.ForeColor;
        this.CalendarMonthBackground = dataGridViewCellStyle.BackColor;

    }

    public int EditingControlRowIndex
    {

        get { return rowIndexNum; }
        set { rowIndexNum = value; }
    }


    public bool EditingControlWantsInputKey(Keys key, bool dataGridViewWantsInputKey)
    {

        // Let the DateTimePicker handle the keys listed.
        switch (key & Keys.KeyCode)
        {
            case Keys.Left:
            case Keys.Up:
            case Keys.Down:
            case Keys.Right:
            case Keys.Home:
            case Keys.End:
            case Keys.PageDown:
            case Keys.PageUp:


                return true;
            default:
                return false;
        }

    }


    public void PrepareEditingControlForEdit(bool selectAll)
    {
        // No preparation needs to be done.

    }

    public bool RepositionEditingControlOnValueChange
    {

        get { return false; }
    }


    public DataGridView EditingControlDataGridView
    {

        get { return dataGridViewControl; }
        set { dataGridViewControl = value; }
    }


    public bool EditingControlValueChanged
    {

        get { return valueIsChanged; }
        set { valueIsChanged = value; }
    }


    public Cursor EditingControlCursor
    {

        get { return base.Cursor; }
    }
    Cursor IDataGridViewEditingControl.EditingPanelCursor
    {
        get { return EditingControlCursor; }
    }



    protected override void OnValueChanged(EventArgs eventargs)
    {
        // Notify the DataGridView that the contents of the cell have changed.
        valueIsChanged = true;

        this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
        base.OnValueChanged(eventargs);
    }

}
#endregion


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-09-23 15:14:11 By : lamaka.tor
 


 

No. 4



โพสกระทู้ ( 201 )
บทความ ( 0 )



สถานะออฟไลน์


ของผมไม่ขึ้นนะครับ

กก

ถ้าแก้ที่properties จะแก้ตรงไหนครับพอจะแนะนำได้ไหมครับหรือพอจะมีวิธีอื่นไหม
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-09-23 15:52:33 By : ์New_User
 


 

No. 5



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

Code (VB.NET)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      DateDateTimePicker.Value = now

       Me.Validate()
       Me.MEMBERBindingSource1.AddNew()
       Me.TableAdapterManager1.UpdateAll(Me.Housing_FundDataSet1)
   End Sub

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-09-23 18:01:28 By : lamaka.tor
 


 

No. 6



โพสกระทู้ ( 201 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณครับ พี่ lamaka.tor
ผมใช้ DateDateTimePicker.Value = now ตามที่พี่แนะนำใช้งานได้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-09-24 14:07:38 By : ์New_User
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอถามเรื่อง Data Binding ใน VB.Net เวลากด save ข้อมูลDateDateTimePickerมันไม่ insert ลงใน Table ให้ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่