Hi
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":
This is how I'm calling it: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 ''#.. ''#...
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 itCode:Using oSQL As New clsSQL(My.Settings.projectConnectionString) If oSQL.OpenConnection Then strSQL = "INSERT INTO ficheiros (nome_ficheiro, caminho_ficheiro, checksum) values ('nomefich', 'nomepath', '000')" oSQL.Execute(strSQL) Else MsgBox("fail") End If End Using
For instance, I can execute perfectly the next function without any kind of problems:
And this is how I'm calling it: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
Probably, I just need another pair of eyes, 'cause I can't see what am I doing wrong :|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
Could this be related to the database and not to my code?
Thanks





Reply With Quote