작동하지 않습니다. 레이블은 기본값으로 만 돌아갑니다. 문제가 뭐라고 생각하니?vb.net을 사용하여 다른 양식에서 레이블 값 가져 오기
Private Sub ProfileControl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim conn As New MySqlConnection(ServerString)
Dim dap As New MySqlDataAdapter("select * from employee where LogInID = '" & Main.ID.Text & "'", conn)
Dim dt As New DataTable
dap.Fill(dt)
employeenum = dt.Rows(0).Item("EmployeeID")
position = dt.Rows(0).Item("Position")
employeename = dt.Rows(0).Item("FirstName") + " " + dt.Rows(0).Item("LastName")
lblemployeename.Text = employeename
lblemployeenum.Text = employeenum
EmpPosition.Text = position
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
그리고 이것이다 :이 레이블의 값을 생성 형태는 사실 내가 여기
내 데이터베이스로 MySQL을 사용하고
: 좋아
이 내 코드입니다 3 개의 라벨의 값을 얻어 온다.
Private Sub addsavebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addsavebutton.Click
Dim profile As New ProfileControl
If txtbranchname.Text <> "" Then
If addsavebutton.Text = "ADD" Then
Dim zero As Integer = 0
Dim SQLStatement As String = "INSERT INTO branch(BranchName,Centers)VALUES('" & txtbranchname.Text & "','0') "
SaveCenter(SQLStatement)
logdate = Convert.ToDateTime(Date.Now).ToString("yyyy-MM-dd hh:mm:ss")
logdate2 = Format(Date.Now, "yyyy-MM-dd")
status = "Added Branch " + txtbranchname.Text
SQLStatement = "INSERT INTO log(EmployeeID,Name,EmployeePosition,Date,DateTime,Status)VALUES('" & profile.lblemployeenum.Text & "','" & profile.lblemployeename.Text & "','" & profile.EmpPosition.Text & "','" & logdate2 & "','" & logdate & "','" & status & "')"
Savelog(SQLStatement)
txtbranchname.Clear()
ElseIf addsavebutton.Text = "SAVE" Then
Dim Query As String
Dim con As MySqlConnection = New MySqlConnection(ServerString)
con.Open()
Query = "UPDATE branch SET BranchName = '" & txtbranchname.Text & "' WHERE BranchCode = '" & txtbranchcode.Text & "'"
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
Dim i As Integer = cmd.ExecuteNonQuery()
If (i > 0) Then
'success
Dim Successtext As New MsgSuccess
Successtext.PassedText = "Record is Successfully Updated"
Successtext.ShowDialog()
Dim SQLStatement As String
logdate = Convert.ToDateTime(Date.Now).ToString("yyyy-MM-dd hh:mm:ss")
logdate2 = Format(Date.Now, "yyyy-MM-dd")
status = "Updated Branch: " + txtbranchcode.Text + ", " + txtbranchname.Text
SQLStatement = "INSERT INTO log(EmployeeID,Name,EmployeePosition,Date,DateTime,Status)VALUES('" & profile.lblemployeenum.Text & "','" & profile.lblemployeename.Text & "','" & Main.lbldate.Text & "','" & logdate2 & "','" & logdate & "','" & status & "')"
Savelog(SQLStatement)
srchTextBox.Clear()
con.Close()
Else
'error
Dim Errortext As New Msgerror
Errortext.PassedText = "Record is not Updated"
Errortext.ShowDialog()
End If
End If
Else
Dim Errortext As New Msgerror
Errortext.PassedText = "All Entries with * must be filled"
Errortext.ShowDialog()
End If
End Sub
을 레이블에 할당하거나 자신의 클래스를 만드는 것이 창조 고려해야은 개인이고, 당신이해야 그런 식으로 유지하면 각 레이블마다 하나씩 컨트롤의 텍스트 값을 노출하는 3 개의 공용 속성을 작성해야합니다. –