Note that there are some explanatory texts on larger screens.

plurals
  1. POExecuteNonQuery not executing - vb.net
    text
    copied!<p>I'm trying to execute a SQL command, but I just can't find out why this is not working. This is how I defined the "execute" function in my class named "clsSQL":</p> <pre><code> ''#... Private m_sConnectionString As String = String.Empty ''#... Friend WithEvents m_objConnection As SqlConnection Friend WithEvents m_objCommand As SqlCommand ''#... Public Function OpenConnection() As Boolean Try m_objConnection = New SqlConnection(m_sConnectionString) m_objConnection.Open() Select Case m_objConnection.State Case Data.ConnectionState.Open : Return True Case Else : Return False End Select Catch ex As Exception RaiseEvent OnError("OpenConnection", ex) End Try End Function Public Function Execute(ByVal sQuery As String) As Boolean Try #If DEBUG_MODE Then Debug.WriteLine(sQuery) #End If m_objCommand = New SqlCommand(sQuery, m_objConnection) m_objCommand.ExecuteNonQuery() m_objCommand = Nothing Return True Catch ex As Exception RaiseEvent OnError("Execute", ex) End Try End Function ''#.. ''#... </code></pre> <p>This is how I'm calling it:</p> <pre><code> Using oSQL As New clsSQL(My.Settings.projectConnectionString) If oSQL.OpenConnection Then strSQL = "INSERT INTO ... blablabla..." oSQL.Execute(strSQL) End If End Using </code></pre> <p>The code raises no error, it is just not saving the data in the database. The error is not in the SQL command, I've manually tested it ;)</p> <p>For instance, I can execute perfectly the next function without any kind of problems:</p> <pre><code> Public Function ToDataGrid(ByVal oDataGrid As DataGridView, _ ByVal sQuery As String, _ Optional ByVal sTable As String = "") As Boolean Try #If DEBUG_MODE Then Debug.WriteLine(sQuery) #End If Dim objDataSet As New DataSet objDataSet = ToDataSet(sQuery, sTable) oDataGrid.DataSource = objDataSet.Tables(0) objDataSet.Dispose() objDataSet = Nothing Return True Catch ex As Exception RaiseEvent OnError("ToDataGrid", ex) End Try End Function </code></pre> <p>And this is how I'm calling it:</p> <pre><code>Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Using oSQL As New clsSQL(My.Settings.projectConnectionString) If oSQL.OpenConnection Then oSQL.ToDataGrid(Me.DataGridView, "select * from table") End If End Using End Sub </code></pre> <p>Probably, I just need another pair of eyes, 'cause I can't see what am I doing wrong :|</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload