程序健壮性最基本要求就是程序错误的处理与捕捉,在ASP.NET中,错误的处理有和其他编程语言一样的机制,可以使用Try…Catch… Finally等方式,这一点和ASP相比具有较大的进步。而且,使用这些错误处理方法,可以大大提高程序的可读性和程序调试速度,在这几个优势结合的情况下,我们更加应该注意这一点。
Dim myInputString As String = " Alex"
myOutputString = myOutputString & myInputString
Response.Write(myoutputString)
Append和其他语言的Append一样,就是在字符串最后增加其他字符。
sb.append( "<table border=\\\'1\\\' width=\\\'80%\\\'>" )
For i = 0 To RowCount - 1
sb.Append("<tr>")
For k = 0 To ColCount - 1
sb.Append("<td>")
sb.Append( dt.Rows(i).Item(k, DataRowVersion.Current).toString())
sb.Append( "</td>" )
Next
sb.Append("<tr>")
Next
sb.Append( "</table>")
Dim strOutput as String = sb.ToString()
lblCompany.Text = strOutput
Dim sb As System.Text.StringBuilder
Dim varother As Integer
varother=9999
sb =new System.Text.StringBuilder()
sb.append("<font color=\\\'blue\\\'>可以Append其他类型:</font>")
sb.append(varother)
Response.write(sb.toString())
End Sub
Insert方法,可以在指定位置插入其他字符,使用方法:Insert(插入位置,插入字符);
Remove方法,可以在指定位置删除指定字数字符,使用方法:Remove(其实位置,字符数);
Replace方法,可以替换指定字符,使用方法:replace(被替换字符串,替换字符串)
Dim myCommand As SqlCommand = new SqlCommand("Select pub_id, pub_name From publishers", myConnection)
Dim myDataReader As SqlDataReader
Try
myConnection.Open()
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
DropDownList1.DataSource = myDataReader
DropDownList1.DataBind()
Catch myException As Exception
Response.Write("An error has occurred: " & myException.ToString())
Finally
If Not myDataReader Is Nothing Then
\\\'关闭DataReader
myDataReader.Close()
End If
End Try
Dim myCommand As SqlCommand = new SqlCommand("Select pub_id, pub_name From publishers", myConnection)
Try
myConnection.Open()
DropDownList1.DataSource = myCommand.ExecuteReader()
DropDownList1.DataBind()
Catch myException As Exception
Response.Write("An error has occurred: " & myException.ToString())
Finally
If Not myConnection Is Nothing AndAlso ((myConnection.State And ConnectionState.Open) = ConnectionState.Open) Then
myConnection.Close()
End If
End Try