From the MSDN Article I read I should be using the StringBuilder rather than concatenating a normal string. However I do not know why I get the following errer: “Variable ‘ShowString’ is used before it has been assigned a value. A null reference exception could result at runtime.”
The following code:
Dim ShowString As StringBuilder
Dim ShowSort As StringBuilder
'ShowString.
ShowString.Append("POS,tdate,Product")
'========Show Options==================
If CheckBox1.Checked = True Then
ShowString.Append(",tkey")
End If
If CheckBox2.Checked = True Then
ShowString.Append(",Price")
End If
If CheckBox3.Checked = True Then
ShowString.Append(",FID")
End If
'==========End Show Options============
'=========Sort Options================
If RadioButton1.Checked = True Then
ShowSort.Append("tdate")
If RadioButton8.Checked Then
ShowSort.Append(" desc")
End If
End If
If RadioButton2.Checked = True Then
ShowSort.Append("tkey")
If RadioButton8.Checked Then
ShowSort.Append(" desc")
End If
End If
'=======End Sort Options=============
Dim sort As String = ShowSort.ToString
Dim show As String = ShowString.ToString
Try
con.Open()
Catch ex As Exception
MessageBox.Show("Please contact support, there was a database error with the following message: " & ex.Message, "Cannot Connect", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
You need to assign a
StringBuilderobject to the references:Or: