开发者

How to change dateformat in VB.NET 2010?

I am using a DateTimePicker control in my form.

By selecting a date, it should开发者_开发百科 be inserted in an MS SQL database. But, the date format in VB is (DMY) and is different from the format in MS SQL (YMD) !!

How can I resolve this?


Use parametrised query to solve the problem. The following is an example:

Dim cmd as SqlCommand = new SqlCommand(
   "INSERT INTO table_name (username, logindate) 
    VALUES (@USERNAME, @DATE)", conn)

cmd.Parameters.AddWithValue("@USERNAME", tbUserName.Text)
cmd.Parameters.AddWithValue("@DATE", dateTimePicker.Value)

int i = cmd.ExecuteNonQuery();

However, if you are interested in formatting your date value, the following articles may help you:

Standard Date and Time Format Strings

Custom Date and Time Format Strings

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜