I´m trying to develop a system that reproduces a quiz game. Basically it´s developed with vb (vs 2017) and microsoft access database.
In certain point after the player choose the wrong answer, the system compiles the results with name, amount of righ questions and maximum score.
Aftewards it should record in the database the results., but, it doensnt make it.
My code follow bellow:
Sub RegistraJogo()
Try
Dim Conn As New OleDbConnection
Conn.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source=DbDesafioQuiz.accdb"
Conn.Open()
Dim cmd = Conn.CreateCommand
cmd.CommandText = "INSERT INTO TbRecordes (Nome, Data, Pontos, Acertadas) VALUES (#Jogador, #Datas, #Pts, #Corretas)"
cmd.Parameters.AddWithValue("#Jogador", LbJogador.Text) 'nome do jogador
cmd.Parameters.AddWithValue("#Datas", CStr(Now())) 'data do jogo
cmd.Parameters.AddWithValue("#Pts", CStr(PontosTotais * QtdRespondidas)) 'variáveis com valores de pontos e qtd de questões resp
cmd.Parameters.AddWithValue("#Corretas", QtdRespondidas) 'qtd de questões respondidas
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
receivedData = 0
End Sub
Someone could help me, indicanting what i´m doing wrong? Thanks in advance.
I´ve changed the connection string, putting the complete address of database, like:
"c:\temp\dbdesafioquiz.accdb"
Related
Currently I'm develop a system using VB.NET. I have the following query for UPDATE. This query is work when I run in SQL Developer
UPDATE CCS2_TBL_INSPECTION_STANDARD SET CCSEQREVITEM = :CCSEQREVITEM,
CCSREVEFFECTIVEDATE = TO_DATE(:CCSREVEFFECTIVEDATE,'DD/MM/YYYY') WHERE
CCSEQID = :CCSEQID
But when I try applied this query in VB.net, its not work. Actually the flow for this update function is work but when I update the data, it is not working. For example, I want update name from 'Ali' to 'Abu', when I click the update button, there popup windows says that "Update success" but the name is not change to 'Abu', it still 'Ali'. There no error when I execute. Anyone know? Below VB.net code:
Protected Sub editInspectionRev(eqid As String)
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE CCS2_TBL_INSPECTION_STANDARD")
xSQL.AppendLine("SET")
xSQL.AppendLine("CCSEQREVITEM = :CCSEQREVITEM, CCSREVEFFECTIVEDATE = TO_DATE(:CCSREVEFFECTIVEDATE,'DD/MM/YYYY')")
xSQL.AppendLine("WHERE CCSEQID = :CCSEQID")
Using cn As New OracleConnection(ConString)
cn.Open()
Dim cmd As New OracleCommand(xSQL.ToString, cn)
cmd.Connection = cn
cmd.Parameters.Add(":CCSEQREVITEM", txtRevContent.Text)
cmd.Parameters.Add(":CCSREVEFFECTIVEDATE", txtRevEffDate.Text)
cmd.Parameters.Add(":CCSEQID", eqid)
cmd.ExecuteNonQuery()
cn.Close()
End Using
success3.Visible = True
DisplayRevisionDetails()
End Sub
The problem is that you have executed the transaction but failed to COMMIT it. There is an example of the correct method here, which I will reproduce in part below for posterity
Using connection As New OracleConnection(connectionString)
connection.Open()
Dim command As OracleCommand = connection.CreateCommand()
Dim transaction As OracleTransaction
' Start a local transaction
transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted)
' Assign transaction object for a pending local transaction
command.Transaction = transaction
...
command.ExecuteNonQuery()
transaction.Commit()
Observe that we have begun the transaction, and then committed it after executing.
I want to import data from Oracle database to Excel using VBA. I've tried several options I found in here or in the official manual but none of them seem to work for me - I always get the same unspecified runtime error on line with
rs.Open strSQL1, con
or
Set rs = con.Execute(strSQL1)
depending on which one of these two methods I use obviously. Here is the whole code:
Sub data_distribution()
'Setting up the database connection
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL1, strInput, strCon As String
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
strCon = "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=XXX)(PORT=XXX))" & _
"(CONNECT_DATA=(SERVICE_NAME=XXX))); uid=XXX; pwd=XXX;"
'--- Open the above connection string.
con.ConnectionString = strCon
con.Open
'con.Open strCon
'--- Now connection is open and you can use queries to execute them.
'--- It will be open till you close the connection
'Definition of parameter
strInput = InputBox("Insert car_id")
strSQL1 = "select * from car where car_id = " & strInput & ""
'Executing the query
'rs.activeconnection = con
'rs.Open strSQL1, con
Set rs = con.Execute(strSQL1)
rs.Open strSQL1, con
Worksheets("Data").Range("A2").CopyFromRecordset rs
'Closing connection
rs.Close
con.Close
Set con = Nothing
Set rs = Nothing
I was thinking it might be an issue of connecting to the database but if I import/query data manual, it works just fine. For example using this manual
http://blog.mclaughlinsoftware.com/microsoft-excel/how-to-query-oracle-from-excel-2007/
I had to download and configure ODAC for Windows from Oracle site to make it work. I use tsnames.ora to set the path. Wasn't sure if I configured it right but it works so I guess there isn't a problem with the connection in vba either, or is it? (The variables are, of course, set to real values, not "XXX")
The query itself is correct and returns valid results from the database. Libraries necessary to use ADOBD are linked as well. (Microsoft ActiveX Data Objects 2.0 Library)
There is an existing question with the same error but it's unresolved:
Unspecified run time error while executing vba script
I'm guessing it's station/interface specific (I use Excel 2010, SQL developer).
Even though it's been some time I asked the question, here, it's still unresolved so I will answer myself.
The problem was in the car table where one of the attributes was type CLOB (CHARACTER LARGE OBJECT) with lenght over 2000 characters. Excel was unable to cope with that type and the query caused the unspecified error. If I listed all attributes but this one, it all went well.
Good day sirs. I'm trying to retrieve a photo from my access database then load it in a PictureBox but I have this kind of problem which I can't resolve.
I have seen questions similar to mine but I can't understand the solutions given by others as I'm just a newbie. Will someone please help me correct my codes for retrieving image file from access database. Thanks
I'm using access database and Visual Basic 2010.
Here's the code:
Dim arrImage() As Byte
Dim myMS As New IO.MemoryStream
Dim da As New OleDb.OleDbDataAdapter("SELECT *
FROM tblEmp
WHERE EmployeeID= '"
& Me.txtID.Text
& "'", con)
Dim dt As New DataTable
da.Fill(dt)
If dt.Rows.Count > 0 Then
If Not IsDBNull(dt.Rows(0).Item("Picture")) Then
arrImage = dt.Rows(0).Item("Picture")
For Each ar As Byte In arrImage
myMS.WriteByte(ar)
Next
'
inFrm.PictureBox1.Image = Image.FromStream(myMS)
End If
End If
I'm getting a "Parameter is not valid" error from the line
inFrm.PictureBox1.Image = Image.FromStream(myMS)
try replacing the line of code with this
inFrm.PictureBox1.PictureData = myMS.Read
Please note that I am a newbie in WMI, have been researching this issue for most of the day, and even though there are hundres of posts, I am struglling to find any help on this specific problem.
Experiencing an issues using Win32_DiskDrive - Caption and also name functions:
When I execute the VB.script:
Try
Dim connection As New ConnectionOptions
connection.Username = userNameBox.Text
connection.Password = passwordBox.Text
connection.Authority = "ntlmdomain:ms1"
Dim scope As New ManagementScope( _
"\\ms1\root\CIMV2", connection)
scope.Connect()
Dim query As New ObjectQuery( _
"SELECT * FROM Win32_DiskDrive")
Dim searcher As New ManagementObjectSearcher(scope, query)
For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_DiskDrive instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("Caption: {0}", queryObj("Caption"))
Next
it correctly lists the 5 harddrives that I have in the server i am querying.
But when I execute it in asp.net (vb) it lists only the 1 drive.
Dim query4 As New ObjectQuery("Select * from Win32_DiskDrive")
Dim searcher4 As New ManagementObjectSearcher(scope, query4)
For Each queryObj3 As ManagementObject In searcher4.Get()
'Availability
' text15.Text = queryObj3("Name")
text16.Text = queryObj3("Caption")
Next
My resuls are bountd to a textfield, formatted to wrap and multiline.
Regards
Louis van Rooyen
It seems you overrwrite text16.Text again and again, so the result in the end would be the information of the last device only.
Try concatenating the string instead:
' TODO: Use proper string formating instead of simpy string concatenating '
text16.Text = text16.Text & queryObj3("Caption")
We have very old VB6 applications connecting to a Sybase database. Today they are running fine using the Open Client 12 drivers via ODBC connecting to a Sybase ASE 15 servers.
There is a plan on upgrading to the OpenClient 15 drivers and with that version I'm getting this error:
Run-time error '-2147467259(80004005)'
Transaction cannot have multiple recordsets with this cursor type.
Change the cursor type, commit the transaction, or close one of the recordsets.
As I understand searching the internet, the problem is in the Cursors.
In the old drivers in the ODBC configuration manager there was a Performance Tab and we have the Select Method in cursor, but with the new drivers this tab is gone and all we got about cursors is a section in the General tab named Cursor Behavior, in there we have the option Use Cursors checked.
Here is a little code snippet where I can reproduce the problem. All help is appreciated.
Dim conObj As ADODB.Connection
Dim objRs As ADODB.Recordset
Dim objRs2 As ADODB.Recordset
Set conObj = New ADODB.Connection
conObj.ConnectionTimeout = 10
conObj.CommandTimeout = 5
conObj.Provider = "MSDASQL"
conObj.Open "DSN=cdbur32;UID=***;PWD=***;Database=dbsait;WSID=Test;APP=Test"
conObj.CursorLocation = adUseClient
conObj.BeginTrans
Set objRs = New ADODB.Recordset
Set objRs.ActiveConnection = conObj
objRs.Source = "select id_estatus_aplicacion from dbo.cat_sait_estatus_aplicaciones"
objRs.CursorType = ADODB.CursorTypeEnum.adOpenForwardOnly
objRs.LockType = ADODB.LockTypeEnum.adLockReadOnly
objRs.Open
objRs.MoveNext
Debug.Print objRs("id_estatus_aplicacion")
Set objRs2 = New ADODB.Recordset
Set objRs2.ActiveConnection = conObj
objRs2.Source = "select * from dbo.cat_sait_estatus_aplicaciones"
objRs2.CursorType = ADODB.CursorTypeEnum.adOpenForwardOnly
objRs2.LockType = ADODB.LockTypeEnum.adLockReadOnly
objRs2.Open 'error here
objRs.MoveNext
Debug.Print objRs("id_estatus_aplicacion")
conObj.RollbackTrans
objRs.Close
objRs2.Close
Set conObj = Nothing
Does changing lines
objRs.CursorType = ADODB.CursorTypeEnum.adOpenForwardOnly
and
objRs2.CursorType = ADODB.CursorTypeEnum.adOpenForwardOnly
help?
in the end the Sybase guys send us a new drivers and that fixed the problem