I'm not able to write my data when I write them in the textbox and when I choose the value in the combobox .. I do not understand what might be wrong, can you check it? Thank you
Imports System.Data.OleDb
Imports System.Data.SqlClient
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
TxtDataNasc.Text = table.Rows(0)("DOB").ToString().Substring(0, IIf(table.Rows(0)("DOB").ToString().Length > 10, 10, table.Rows(0)("DOB").ToString().Length))
TxtApelido.Text = table.Rows(0)("LastName").ToString
TxtDataForm.Text = table.Rows(0)("GraduateDate").ToString
TxtDataForm.Text = table.Rows(0)("GraduateDate").ToString().Substring(0, IIf(table.Rows(0)("GraduateDate").ToString().Length > 10, 10, table.Rows(0)("GraduateDate").ToString().Length)) ' para tirar a hora do campo e mostrar só a data
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
Public 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.SelectedValue & ", " & _
"Telephone = " & TxtTelefone.Text & ", " & _
"Mobile = " & TxtTelem.Text & ", " & _
"Speciality1 = " & CBEsp1.SelectedValue & ", " & _
"Speciality2 = " & CBEsp2.SelectedValue & " " & _
"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()