<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Import Namespace="System.Data" %>
<%@ Page language="VB" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html><head>
<title>TechRepublic.com - Test</title>
</head><body>
<script language="VB" runat="server">
Dim conn AS SqlConnection
Dim cmd As SqlCommand
Dim connString As String
Dim rvalue As Integer
Public Sub SubmitChanges()
connString = "datasource=LOU8-3590424PATTON;uid=test;
pwd=test;initial catalog=Northwind"
Try
conn = new SqlConnection(connString)
cmd = new SqlCommand("sp_UpdateCustomerPhone", conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@id", SqlDbType.NVarChar, 5)
cmd.Parameters("@id").Value = lblID.Text
cmd.Parameters.Add("@phone", SqlDbType.NVarChar, 24)
cmd.Parameters("@phone").Value = txtPhone.Text
cmd.Parameters.Add("@retvalue",System.Data.SqlDbType.Int)
cmd.Parameters("@retvalue").Direction= ParameterDirection.Output
conn.Open()
cmd.ExecuteNonQuery()
rvalue = System.Convert.ToInt32(cmd.Parameters("@retvalue").Value)
If (rvalue = -1) Then
lblMessage.Text = "Database error duringupdate."
lblMessage.Visible = true
Else
lblMessage.Text = "Data has been updated."
lblMessage.Visible = true
End If
conn.Close()
Catch ex As SqlException
lblMessage.Text = "Error accessing database:" + ex.ToString()
Catch ex As Exception
lblMessage.Text = "Exception: " + ex.ToString()
Finally
If (conn.State = ConnectionState.Open)Then
conn.Close()
End If
conn.Dispose()
End Try
End Sub
Private Sub btnUpdatePhone_Click(sender As Object, eAs
System.Web.UI.WebControls.CommandEventArgs)
SubmitChanges()
End Sub
</script>
<form id="frmTestUpdate"method="post" runat="server">
<asp:Label ID="lblMessage"Visible="False"
runat="server"></asp:Label><br /><br />
<asp:Label ID="lblPhone"runat="server">New Number:</asp:Label>
<asp:TextBox ID="txtPhone"runat="server" /><br/><br />
<asp:Button ID="btnUpdatePhone"Text="Update"
OnCommand="btnUpdatePhone_Click" runat="server"/>
<asp:Label ID="lblID"Visible="False" runat="server">ALFKI</asp:Label>
</form></body></html> |