我想顯示列表視圖中的行數。我試過這段代碼,但不是工作,它會拋出下面的錯誤。我使用MySQL的後端:顯示從列表視圖中的數據表中找到的行數
錯誤:
System.InvalidCastException: Conversion from string " '" to type 'Double' is not valid. ---> System.FormatException: Input string was not in a correct format
VB代碼:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
ViewState("Data") = ""
Using con As New MySqlConnection(constr)
Using cmd As New MySqlCommand("SELECT * FROM school")
Using sda As New MySqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
cmd.CommandTimeout = 0
Using dt As New DataTable()
sda.Fill(dt)
ViewState("Data") = dt
schoollists.DataSource = dt
schoollists.DataBind()
End Using
End Using
End Using
End Using
countResult.Text = (" '" + schoollists.Items.Count + "';")
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
備註部分在VB.NET不使用加號來連接字符串的數字。使用正確的操作符& – Steve
@Steve請詳細說明。我不明白..謝謝.. –