Click to See Complete Forum and Search --> : sqlAdapter in ASP.NET with VB Codes


alexandar
September 15th, 2002, 11:58 PM
Hi Everyone! I can't seem to be able to use the sqlAdapter. I was wandering if the sqlAdapter can link my data in my database to textboxes in ASP.Net? Here are my codes:

From the SqlAdapter:

SELECT Name, Staff_Number, Depart_Code, OT_StartDate, OT_EndDate, OT_StartTime, OT_EndTime, ExtEndTime, ExtEndDate, Remarks, ExtRemarks,
MgrRemarks, Approval, ExtApproval
FROM OT
WHERE (Depart_Code = @label14Param) AND (Approval = 0) AND (ExtApproval = 0) OR
(Depart_Code = @label14Param) AND (Approval = 1) AND (ExtApproval = 0) OR
(Depart_Code = @label14Param) AND (Approval = 1) AND (ExtApproval = 1)

From the VB Code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim DeptTemp As String
Dim sql As String
Dim conn As SqlConnection
Dim dr As SqlDataReader
Dim cmd As New SqlCommand()
Dim NumTemp As String


Me.label14.Text = Session("departTemp")


With (SqlDataAdapter1.SelectCommand.Parameters)
.Item("@label14Param").Value = Me.label14.Text
End With

If Me.CheckBox1.Text = "0" Then
Me.CheckBox1.Checked = False
Else
Me.CheckBox1.Checked = True
End If

If Me.CheckBox2.Text = "0" Then
Me.CheckBox2.Checked = False
Else
Me.CheckBox2.Checked = True
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.BindingContext(DsView21, _
"OT").Position += 1


If Me.CheckBox1.Text = "0" Then
Me.CheckBox1.Checked = False
Else
Me.CheckBox1.Checked = True
End If

If Me.CheckBox2.Text = "0" Then
Me.CheckBox2.Checked = False
Else
Me.CheckBox2.Checked = True
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.BindingContext(DsView21, _
"OT").Position -= 1

If Me.CheckBox1.Text = "0" Then
Me.CheckBox1.Checked = False
Else
Me.CheckBox1.Checked = True
End If

If Me.CheckBox2.Text = "0" Then
Me.CheckBox2.Checked = False
Else
Me.CheckBox2.Checked = True
End If

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim Conn As SqlConnection
Dim Dr As SqlDataReader

Dim EndDate As String
Dim StartTime As String
Dim EndTime As String
Dim ExtEndDate As String
Dim ExtStart As String

Dim ExtRemarks As String
Dim NameTemp As String
Dim ExtApp As String
Dim EmpNo As String
Dim StartDate As String
Dim App As String
Dim Remarks As String
Dim ExtEndTime As String
Dim MRemarks As String

Remarks = Me.txtRemarks.Text
App = Me.CheckBox1.Text
ExtApp = Me.CheckBox2.Text
StartDate = Me.txtStartDate.Text
EmpNo = Me.txtNum.Text
EndDate = Me.txtEndDate.Text
StartTime = Me.txtStartTime.Text
EndTime = Me.txtEndTime.Text
ExtRemarks = Me.txtExtRem.Text
ExtEndDate = Me.txtExtEndDate.Text
NameTemp = Me.txtName.Text
ExtEndTime = Me.txtExtEndTime.Text
MRemarks = Me.txtMgrRem.Text

App = "0"
ExtApp = "0"

If Me.CheckBox1.Checked = True Then
App = "1"
End If

If Me.CheckBox2.Checked = True Then
ExtApp = "1"
End If


Dim StrSQL As String = "UPDATE OT SET Approval = '" & App & "'," & _
"ExtApproval = '" & ExtApp & "', MgrRemarks = '" & MRemarks & "' " & _
"WHERE Name = '" & NameTemp & "' and OT_StartDate = '" & StartDate & "' " & _
"and OT_EndDate = '" & EndDate & "' and OT_StartTime = '" & StartTime & "' and OT_EndTime = '" & EndTime & "'"
Conn = New SqlConnection("Initial Catalog=matrixVB;" & _
"Data Source=x550_1;user id=sa;password=;")


Dim Cmd As New SqlCommand(StrSQL, Conn)
Conn.Open()
Cmd.ExecuteNonQuery()
MsgBox("Record updated to database.")
Conn.Close()
End Sub

End Class

Is there anything wrong with the codes? Please advice me on this. Thanks.

Alexandar