Click here to Skip to main content
15,902,275 members
Home / Discussions / Database
   

Database

 
QuestioncomboBox1.ValueMember = "column1" Pin
myNameIsRon19-Feb-06 11:51
myNameIsRon19-Feb-06 11:51 
AnswerRe: comboBox1.ValueMember = "column1" Pin
Ritesh123419-Feb-06 18:37
Ritesh123419-Feb-06 18:37 
GeneralRe: comboBox1.ValueMember = "column1" Pin
myNameIsRon20-Feb-06 12:50
myNameIsRon20-Feb-06 12:50 
AnswerRe: comboBox1.ValueMember = "column1" Pin
AlexeiXX320-Feb-06 7:18
AlexeiXX320-Feb-06 7:18 
GeneralRe: comboBox1.ValueMember = "column1" Pin
myNameIsRon20-Feb-06 12:45
myNameIsRon20-Feb-06 12:45 
GeneralRe: comboBox1.ValueMember = "column1" Pin
AlexeiXX320-Feb-06 13:41
AlexeiXX320-Feb-06 13:41 
QuestionDate problem Pin
sebastian yeok18-Feb-06 22:41
sebastian yeok18-Feb-06 22:41 
AnswerRe: Date problem Pin
Colin Angus Mackay19-Feb-06 0:41
Colin Angus Mackay19-Feb-06 0:41 
First and foremost: Don't inject values into the SQL string. here's why[^]

Second: You would be better using an ExecuteScalar for this than using ExecuteReader. This is because you are only receiving one value and ExecuteScalar is designed for retrieving one value (the first column of the first row).

Thirdly: You may wish to consider layering your application. It is bad practice to have database code in the same method as something setting user interface controls. For more information search the internet for the Layering Pattern[^]

sebastian yeok wrote:
my Date field in the database formated as 2/15/2006 11:40:46 AM .


No it isn't. What you are seeing is a localised version of the date coming from the SQL Server. This has nothing to do with the way it is stored. So....

Lastly, use a proper DateTime object and pass it to SQL Server as a parameter. That way you do not have to deal with the formatting of the date.

Dim no As DateTime = New DateTime(2006, 2, 15)
Dim myConn As SqlConnection
Dim myCmd As SqlCommand = New SqlCommand
Dim myReader As SqlDataReader
Dim strSQL As String

myConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))
strSQL = "SELECT Author FROM Booktbl WHERE [Date] = @date";
myCmd.CommandText = strSQL

' The parameter is added so that (1) you don't inject the value into the SQL String and
' (2) you don't have to worry about the formatting of the date as the framework will
' do that for you. Notice how @date corresponds to the @date in the strSQL above.
myCmd.Parameters.Add("@date", no)
myConn.Open()
myCmd.Connection = myConn

' Use execute scalar. Remember to check for DBValueNull in case no rows were found
' and to cast the result to what ever type Author is.
Author = myCmd.ExecuteScalar()

myReader.Close()
myConn.Close()
lblShow.Text = Subject


ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?

GeneralRe: Date problem Pin
sebastian yeok19-Feb-06 1:53
sebastian yeok19-Feb-06 1:53 
GeneralRe: Date problem Pin
Colin Angus Mackay19-Feb-06 2:19
Colin Angus Mackay19-Feb-06 2:19 
GeneralRe: Date problem Pin
sebastian yeok19-Feb-06 2:37
sebastian yeok19-Feb-06 2:37 
GeneralRe: Date problem Pin
Colin Angus Mackay19-Feb-06 2:43
Colin Angus Mackay19-Feb-06 2:43 
QuestionHow to indent SQL statements? Pin
sacoskun18-Feb-06 21:19
sacoskun18-Feb-06 21:19 
AnswerRe: How to indent SQL statements? Pin
Colin Angus Mackay19-Feb-06 0:26
Colin Angus Mackay19-Feb-06 0:26 
GeneralRe: How to indent SQL statements? Pin
CWIZO19-Feb-06 1:40
CWIZO19-Feb-06 1:40 
GeneralRe: How to indent SQL statements? Pin
Paul Conrad19-Feb-06 7:45
professionalPaul Conrad19-Feb-06 7:45 
GeneralRe: How to indent SQL statements? Pin
sacoskun20-Feb-06 9:10
sacoskun20-Feb-06 9:10 
Questionmove table record Pin
sebastian yeok18-Feb-06 21:02
sebastian yeok18-Feb-06 21:02 
AnswerRe: move table record Pin
Colin Angus Mackay19-Feb-06 2:47
Colin Angus Mackay19-Feb-06 2:47 
QuestionDifference between two tables Pin
niceguyeddie199917-Feb-06 5:11
niceguyeddie199917-Feb-06 5:11 
AnswerRe: Difference between two tables Pin
Colin Angus Mackay17-Feb-06 5:35
Colin Angus Mackay17-Feb-06 5:35 
GeneralRe: Difference between two tables Pin
niceguyeddie199917-Feb-06 5:38
niceguyeddie199917-Feb-06 5:38 
GeneralRe: Difference between two tables Pin
Colin Angus Mackay17-Feb-06 8:46
Colin Angus Mackay17-Feb-06 8:46 
QuestionUrgent: SQL Server log: Login succeeded for user 'APPL_ACCOUNT'. Connection: Non-Trusted. Pin
devvvy16-Feb-06 17:45
devvvy16-Feb-06 17:45 
AnswerRe: Urgent: SQL Server log: Login succeeded for user 'APPL_ACCOUNT'. Connection: Non-Trusted. Pin
Edbert P19-Feb-06 13:16
Edbert P19-Feb-06 13:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.