Author

Ahmed Samir

Evry1falls is my online name

VB.Net SqlServer DateTime Insertion

VB.Net SqlServer DateTime Insertion 5 of 5

Dealing with Date/Time in VB.Net and SQLServer

It's been a nightmare since i decided to insert DateTime value into Sql Server 2000 DataBase Table Field Type as SmallDateTime.It took me 3 days and nights trying to work it around.I've did everything i know and everything other told me to do.Finally, i figured it out.
Look ....
Say, you have a Vb.Net 2005 Project with a form contains a DateTimePicker Control called (Q3) and Button Called (B3) Text Property as (Insert), and you have Sql Server 2000 DataBase called (Market) with Table Called (Purchase) includes a Field called (EXdt) Type as (SmallDateTime) Length (4), and you want to update it using Ado.Net Online Mode.
1) Calling The Ado.Net for Sql Server DataBase
Imports System.Data.SqlClient
2) Assigning your variables
Dim CN As New SqlClient.SqlConnection
Dim cPur As New SqlClient.SqlCommand
Dim CntRs As Integer
Dim SqlStr As String
3) Connecting your DataBase 'Market' - Form_Load Event


If CN.State = ConnectionState.Open Then CN.Close()
        CN.ConnectionString = "Data Source=Your_Sql_Server_Name;Initial Catalog=Market;Integrated Security=True"
        CN.Open()
4) Connecting your table 'Purchase' - Form_Load Event


SqlStr = "Select * from Purchase"
        With cPur
            .Connection = CN
            .CommandType = CommandType.Text
            .CommandText = SqlStr
        End With
5) Inserting the date within the DateTimePicker Control (Q3) Into Field (EXdt)
SqlStr = "Insert Into Purchase (ExDT) Values ('" & Q3.Value.ToString("yyyy/MM/dd") & "')"
cPur.CommandText = SqlStr


CntRs = cPur.ExecuteNonQuery()
        MsgBox("( " & CntRs & " ) Record(s) Saved")
Congratulations ....
Download The Source Code Via MediaFire Link

If you have any other problem contact me by Comments - or -
you can simply Google me for more solutions (evry1falls - Your Problem)



Visual Basic .Net - Free POS System Project Source Code

Comment Via facebook

Popular posts from this blog

Visual Basic Online Course DevExpress 12.2.4 full for Visual Studio 2010

Visual Basic Online Course The following control could not be licensed: TxTextControl.TextControl

Visual Basic 2010 Read/Write Command Prompt

Visual Basic Online Course - The Microsoft.ACE.OLEDB.12.0 provider is not registered on the local machine

Visual Basic Online Courses DataGridView Add Edit Delete