Question Got hang after clicking on ADD

joesky

New member
Joined
Mar 8, 2009
Messages
1
Programming Experience
1-3
Hi,

I need need help on my program.
I am suppose to do a VB form where it can be able to read, add, update and delete citectSCADA variables from access .

But after entering the following code into my add button. my form jus hang.
i tried F11. But still it didnt tell me the problem about it.


Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click

Dim N As String
Dim T As String
Dim U As String
Dim A As String

N = NAMETextBox.Text
T = TYPEComboBox.SelectedItem
U = UNITComboBox.SelectedItem
A = ADDRTextBox.Text

Dim SQLStr As String
Dim ConnString As String = "Data Source=|DataDirectory|\variable.mdb"

SQLStr = "INSERT into variable (NAME,TYPE,UNIT,ADDR) VALUES (@name,@type,@unit,@addr)"
Dim SQLConn As New SqlConnection()
Dim SQLCmd As New SqlCommand()
SQLConn.ConnectionString = ConnString
SQLConn.Open()

SQLCmd.Connection = SQLConn
SQLCmd.CommandText = SQLStr
SQLCmd.Parameters.AddWithValue("@name", N)
SQLCmd.Parameters.AddWithValue("@type", T)
SQLCmd.Parameters.AddWithValue("@unit", U)
SQLCmd.Parameters.AddWithValue("@addr", A)
Try
SQLCmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
SQLConn.Close()
End Try



'Me.VariableDataSet.Clear()
'Me.VariableTableAdapter.Fill(Me.VariableDataSet.variable)



End Sub
 
There's no coding to check if valid data is being passed to your stored procedure parameters.

Also add this to your command object

SqlCmd.CommandType = CommandType.StoredProcedure
 
Back
Top