I have here a form with several textbox and some combobox. What happens when I insert a code and populate the textbox with birth date appears to me in this 01/01/1900 00:00:00
format and I just want the date to appear.
Can you help me? the names that appear there like DoctorBasic and DoctorEnterpriseDetails are names of tables and the DBO is the column with the dates of birth.
Public Class Form1
Public Sub TxtCodigoMed_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TxtCodigoMed.KeyPress
If e.KeyChar.ToString = ChrW(Keys.Enter) Then ' Enter para pesquisar
TxtCodigoMed.Focus()
e.Handled = True
CarregarDados()
End If
End Sub
Public Sub CarregarDados()
'LblVazia.Text =
Dim cnnstr As SqlConnection = New SqlConnection("Data Source=****;Initial Catalog=***;user=**;password=****")
Dim myCommand As String
Dim cmd As SqlCommand
Dim da As New System.Data.SqlClient.SqlDataAdapter(cmd)
Dim table = New DataTable
myCommand = "SELECT * FROM DoctorBasic INNER JOIN DoctorEnterpriseDetails ON DoctorBasic.DoctorId = DoctorEnterpriseDetails.DoctorId WHERE EnterpriseId = 26 AND Code = " & TxtCodigoMed.Text
cnnstr.Open()
cmd = New SqlCommand(myCommand, cnnstr)
da.SelectCommand = cmd
da.Fill(table)
TxtPrimeiroNome.Text = table.Rows(0)("FirstName").ToString
TxtApelido.Text = table.Rows(0)("LastName").ToString
TxtNomeComp.Text = table.Rows(0)("FullName").ToString
TxtDataNasc.Text = table.Rows(0)("DOB").ToString
TxtApelido.Text = table.Rows(0)("LastName").ToString
TxtDataForm.Text = table.Rows(0)("GraduateDate").ToString
TxtGrauForm.Text = table.Rows(0)("Degree").ToString
TxtTelefone.Text = table.Rows(0)("Telephone").ToString
TxtTelem.Text = table.Rows(0)("Mobile").ToString
TxtMail.Text = table.Rows(0)("Emailid").ToString
TxtObs.Text = table.Rows(0)("Observation").ToString
TxtLusov.Text = table.Rows(0)("Lusov").ToString
Me.DoctorsAddressTableAdapter.Fill(Me.GSM81DataSet.DoctorsAddress, Me.TxtCodigoMed.Text.ToString) 'carrega a grid através da pesquisa do codigo do médico
cnnstr.Close()
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'GSM81DataSet.GroupType' table. You can move, or remove it, as needed.
Me.GroupTypeTableAdapter.Fill(Me.GSM81DataSet.GroupType)
'TODO: This line of code loads data into the 'GSM81DataSet2.Rank' table. You can move, or remove it, as needed.
Me.RankTableAdapter.Fill(Me.GSM81DataSet2.Rank)
'TODO: This line of code loads data into the 'GSM81DataSet1.PrescibingPotential' table. You can move, or remove it, as needed.
Me.PrescibingPotentialTableAdapter.Fill(Me.GSM81DataSet1.PrescibingPotential)
'TODO: This line of code loads data into the 'GSM81DataSet.Speciality' table. You can move, or remove it, as needed.
Me.SpecialityTableAdapter.Fill(Me.GSM81DataSet.Speciality)
End Sub
Public Sub GravarDoctorBasic()
Dim myConnectionString As SqlConnection = New SqlConnection("Data Source=****;Initial Catalog=***;user=**;password=***")
Dim myCommand As String
Dim cmd As SqlCommand
myCommand = "UPDATE DoctorBasic SET " & _
"Lusov = '" & TxtLusov.Text & "', " & _
"FirstName = '" & TxtPrimeiroNome.Text & "', " & _
"LastName = '" & TxtApelido.Text & "', " & _
"FullName = '" & TxtNomeComp.Text & "', " & _
"DOB = " & TxtDataNasc.Text.ToString & ", " & _
"GraduateDate = '" & TxtDataForm.Text.ToString & "', " & _
"Emailid = '" & TxtMail.Text & "', " & _
"Degree = '" & TxtGrauForm.Text & "', " & _
"Observation = '" & TxtObs.Text & "' " & _
"WHERE DoctorId = " & TxtCodigoMed.Text.ToString
cmd = New SqlCommand(myCommand, myConnectionString)
MsgBox(myCommand)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
End Sub
Public Sub GravarDoctorEnterpriseDetails()
Dim myConnectionString As SqlConnection = New SqlConnection("Data Source=****;Initial Catalog=****;user=****;password=*******")
Dim myCommand As String
Dim cmd As SqlCommand
myCommand = "UPDATE DoctorEnterpriseDetails SET " & _
"RankId = " & CBSelec.ValueMember & ", " & _
"GroupId = " & CBCateg.ValueMember & ", " & _
"PrescribingPotential = " & CBPP.ValueMember & ", " & _
"Telephone = " & TxtTelefone.Text & ", " & _
"Mobile = " & TxtTelem.Text & ", " & _
"Speciality1 = " & CBEsp1.ValueMember & ", " & _
"Speciality2 = " & CBEsp2.ValueMember & " " & _
"WHERE DoctorId = " & TxtCodigoMed.Text.ToString
cmd = New SqlCommand(myCommand, myConnectionString)
' MsgBox(myCommand)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
End Sub
Public Sub btnGravar_Click(sender As System.Object, e As System.EventArgs) Handles btnGravar.Click
GravarDoctorBasic()
GravarDoctorEnterpriseDetails()
End Sub
End Class