0

Hello friends plz help again
How to coding in save button and how to convert the database in SQL Server 2005 in DropDown List becoz in sql take date in mm\dd\yy and in asp.net i m create the form dd\mm\yy? plz help me...

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by simi pillai
0

You must first get the value in the database then set that value.
For example:

'getValue is a function that will get a scalar value from you database.
Dim pDate as Date = getValue("Select getDate() as date",commandtype.text)

'if you want to display it in a label with your desired format
label1.text = format(pDate,"dd\mm\yy")
0

As far i understood you are asking for the code to save values from form to sql server 2005, and you have the date in dd/mm/yy format.
So you need to format date into sql date format while writing code for saving.
and you need to format date while retrieving also.
For example you have taken calender and two text box to save data into database.

so this will be the code :


boolean save()

Dim IsSaved As Boolean = False
Dim ConStr As String = "server=(server name);database=(your database name); user id=user id; password=password "
Dim Con As New System.Data.SqlClient.SqlConnection(ConStr)
Dim str As String = "insert into (table name) values('" & txtName.Text & " ','" & txtPhoneNo.Text & "','" & Format(Calendar1.SelectedDate, "dd\mm\yy") & "',')"
Dim cmd As New System.Data.SqlClient.SqlCommand(str, Con)
Try
Con.Open()
cmd.ExecuteNonQuery()
IsSaved = True
Catch ex As Exception

MsgBox(ex.Message)

Finally
Con.Close()
End Try
end sub

0

select CONVERT(VARCHAR, date1, 101) AS Date
date1 ........variable for date used in database

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.