I have a problem adding data oracle database,it's show me this message(" https://ufile.io/lzpuj ") Run-time ORA-00904:"EMPCODE": invalid identifier.
This is Cody:
Dim connEmp As ADODB.Connection
Dim rsEmp As ADODB.Recordset
Private Sub Command1_Click()
Set rsEmp = New ADODB.Recordset
rsEmp.Open "select * from tablebooks where empcode = '" & Text1.Text & "'",
connEmp, adOpenKeyset, adLockReadOnly, adCmdText
If rsEmp.RecordCount <> 0 Then
MsgBox " ! åÐÇ ÇáßÊÇÈ ãæÌæÏ ÈÇáÝÚá "
rsEmp.Close
Set rsEmp = Nothing
Exit Sub
Else
Set rsEmp = New ADODB.Recordset
rsEmp.Open "select * from tablebooks where empcode = '" & Text1.Text & "'",
connEmp, adOpenKeyset, adLockPessimistic, adCmdText
rsEmp.AddNew
rsEmp!Book_no = Val(Trim(Text1.Text))
rsEmp!Book_name = Trim(Text2.Text)
rsEmp!Author_name = Trim(Text10.Text)
rsEmp!Edition_no = Val(Trim(Text3.Text))
rsEmp!Publisher_place = Trim(Text11.Text)
rsEmp!Part_no = Val(Trim(Text5.Text))
rsEmp!Book_cost = Trim(Text6.Text)
rsEmp!Place_book = Trim(Text7.Text)
rsEmp!Note = Trim(Text9.Text)
rsEmp!Date_publishing = DTPicker1.Value
rsEmp!Subject = Trim(Combo4.Text)
rsEmp!State = Trim(Combo4.Text)
rsEmp.Update
connEmp.Execute "commit"
rsEmp.Close
Set rsEmp = Nothing
Label11.Visible = True
Label11 = " ! ÊãÊ ÇáÅÖÇÝÉ ÈäÌÇÍ "
End If
End Sub
First make sure empcode is exactly the right column name.
Then fix your code. You have two big issues:
It's crazy-vulnerable to Sql Injection attacks.
It tries to re-open the same command on the same connection in the ELSE block for no reason.
The exact fix for #1 depends on which provider you are using (Ole vs Odbc), but this link might help:
Call a parameterized Oracle query from ADODB in Classic ASP
For #2, this is somewhat better:
Dim connEmp As ADODB.Connection
Dim rsEmp As ADODB.Recordset
Private Sub Command1_Click()
Set rsEmp = New ADODB.Recordset
'TODO: Use parameterized query here!
rsEmp.Open "select * from tablebooks where empcode = #empcode '" & Text1.Text & "'",
connEmp, adOpenKeyset, adLockReadOnly, adCmdText
If rsEmp.RecordCount <> 0 Then
MsgBox " ! åÐÇ ÇáßÊÇÈ ãæÌæÏ ÈÇáÝÚá "
rsEmp.Close
Set rsEmp = Nothing
Exit Sub
End If
rsEmp.AddNew
rsEmp!Book_no = Val(Trim(Text1.Text))
rsEmp!Book_name = Trim(Text2.Text)
rsEmp!Author_name = Trim(Text10.Text)
rsEmp!Edition_no = Val(Trim(Text3.Text))
rsEmp!Publisher_place = Trim(Text11.Text)
rsEmp!Part_no = Val(Trim(Text5.Text))
rsEmp!Book_cost = Trim(Text6.Text)
rsEmp!Place_book = Trim(Text7.Text)
rsEmp!Note = Trim(Text9.Text)
rsEmp!Date_publishing = DTPicker1.Value
rsEmp!Subject = Trim(Combo4.Text)
rsEmp!State = Trim(Combo4.Text)
rsEmp.Update
connEmp.Execute "commit"
rsEmp.Close
Set rsEmp = Nothing
Label11.Visible = True
Label11 = " ! ÊãÊ ÇáÅÖÇÝÉ ÈäÌÇÍ "
End Sub
I am successfully able to download the defects using the below code, but how to get the count of linked TCs with status 'Failed or Blocked' against each defect?
Sub GetDefectsByFilter()
On Error Resume Next
Dim a
Dim intIndex As Integer
Dim sngPercent As Single
Dim BugFactory, BugList, BgFilter
Dim Response As VbMsgBoxResult
Dim DefectID As String
If TDC Is Nothing Then ConnecttoQC
Set BugFactory = TDC.BugFactory
Set BgFilter = BugFactory.Filter
DefectID = frmDefectFilter.txtDefectID
BgFilter.Filter("BG_BUG_ID") = DefectID
Set BugList = BgFilter.NewList
Dim Bug, Row, Count As Integer
Count = 1
Row = 2
ActiveSheet.Cells(1, 1).Value = "Defect ID"
ActiveSheet.Cells(1, 2).Value = "Application"
ActiveSheet.Cells(1, 3).Value = "Status"
For Each Bug In BugList
ActiveSheet.Cells(Row, 1).Value = Bug.Field("BG_BUG_ID")
ActiveSheet.Cells(Row, 2).Value = Bug.Field("BG_USER_06")
ActiveSheet.Cells(Row, 3).Value = Bug.Field("BG_STATUS")
Row = Row + 1
Count = Count + 1
Next
frmDefectFilter.Hide
End Sub
Thanks #Roland. The below code snippet helped me.
Sub ViewLinks()
'------------------------------------------------------
' Output all bug links.
Dim BugF As BugFactory, bList As List
Dim aBug As Bug
Dim bugL As ILinkable, LinkList As List, linkF As LinkFactory
'tdc is the global TDConnection object.
Set BugF = tdc.BugFactory
Set bList = BugF.NewList("")
For Each aBug In bList
'Cast the Bug object to an ILinkable reference
' to get the link factory.
Set bugL = aBug
Set linkF = bugL.LinkFactory
Set LinkList = linkF.NewList("")
Dim SourceObj As Object, TargetObj As Object, InitObj As Object, lnk As Link
Debug.Print: Debug.Print "---------------------------------"
Debug.Print "Source Type"; Tab; "ID"; Tab; "Target Type"; _
Tab; "ID"; Tab; "Initiated by"
For Each lnk In LinkList
With lnk
Set SourceObj = .SourceEntity
Set TargetObj = .TargetEntity
Set InitObj = .LinkedByEntity
Debug.Print TypeName(SourceObj); Tab; CStr(SourceObj.ID); _
Tab; TypeName(TargetObj); Tab; CStr(TargetObj.ID); _
Tab; TypeName(InitObj); Spc(3); InitObj.ID
End With
Next lnk
Next aBug
End Sub
This is my first VB6 application. My problem is there is no helpful example of writing data (including current date & time) from a form to an Access database. Here's my code based on all my research from different websites.
If you can't understand my code or if it is wrong, please show me a working example.
Private Sub Command1_Click()
Dim conConnection As New ADODB.Connection
Dim cmdCommand As New ADODB.Command
Dim rstRecordSet As New ADODB.Recordset
Dim logInId As Integer
Dim guardId As String
Dim studentId As String
Dim laptopName As String
Dim laptopBrand As String
Dim logInDate As Date
Dim logInTime As Date
guardId = Text2.Text
studentId = Text3.Text
laptopName = Text4.Text
laptopBrand = Text5.Text
logInDate = DateVal(Now)
logInTime = TimeVal(Now)
conConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
App.Path & "\" & "Database.accdb;Mode=Read|Write"
conConnection.CursorLocation = adUseClient
conConnection.Open
rstRecordSet.Open "laptopLoggedInLoggedOutInfo", conConnection
logInId = rstRecordSet.RecordCount
With cmdCommand
.ActiveConnection = conConnection
.CommandType = adCmdText
'f means field
.CommandText = "INSERT INTO laptopLoggedInLoggedOutInfo(f1,f2,f3,f4,f5,f6,f7) VALUES (?,?,?,?,?,?,?) "
.Prepared = True
.Parameters.Append .CreateParameter("f1", adInteger, adParamInput, , logInId + 1)
.Parameters.Append .CreateParameter("f2", adChar, adParamInput, 20, guardId)
.Parameters.Append .CreateParameter("f3", adChar, adParamInput, 20, studentId)
.Parameters.Append .CreateParameter("f4", adChar, adParamInput, 20, laptopName)
.Parameters.Append .CreateParameter("f5", adChar, adParamInput, 20, laptopBrand)
.Parameters.Append .CreateParameter("f6", adDate, adParamInput, , logInDate)
.Parameters.Append .CreateParameter("f7", adDate, adParamInput, , logInTime)
Set rstRecordSet = cmdCommand.Execute
End With
conConnection.Close
Set conConnection = Nothing
Set cmdCommand = Nothing
Set rstRecordSet = Nothing
End Sub
I've made in-line comments on your code:
Private Sub Command1_Click()
Whilst this doesn't matter for this particular example, generally don't declare object variables "As New". It is better if you instantiate them manually. Essentially, "As New" declared variables are checked every time you try to use a property or method on them, and if the variable Is Nothing, it creates a new instance. This may not necessarily be what you intend.
Dim conConnection As New ADODB.Connection
Dim cmdCommand As New ADODB.Command
Dim rstRecordSet As New ADODB.Recordset
Dim logInId As Integer
Dim guardId As String
Dim studentId As String
Dim laptopName As String
Dim laptopBrand As String
Dim logInDate As Date
Dim logInTime As Date
guardId = Text2.Text
studentId = Text3.Text
laptopName = Text4.Text
laptopBrand = Text5.Text
logInDate = DateVal(Now)
logInTime = TimeVal(Now)
Make sure that the Data Source substring is points to your Access database.
conConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
App.Path & "\" & "Database.accdb;Mode=Read|Write"
conConnection.CursorLocation = adUseClient
conConnection.Open
I see that you are using a recordset just to receive a count of records in logInId. I really wouldn't use this as an ID. If you delete records from the table, then your ID will become smaller. Generally, if you want a unique ID, you must ensure that the ID always increments.
rstRecordSet.Open "laptopLoggedInLoggedOutInfo", conConnection
logInId = rstRecordSet.RecordCount
My suggestion: use "SELECT MAX(f1) FROM laptopLoggedInLoggedOutInfo", and retrieve the first value, ensuring that if the value is null, it returns zero, e.g.
rstRecordSet.Open "SELECT MAX(logInId) FROM laptopLoggedInLoggedOutInfo", conConnection
logInId = IIf(IsNull(rstRecordSet.Fields(0)), 0, IsNull(rstRecordSet.Fields(0)))
With cmdCommand
.ActiveConnection = conConnection
.CommandType = adCmdText
'f means field
Are these really your fieldnames: f1, f2, f2, etc.? I would be surprised. Replace them with the correct field names.
.CommandText = "INSERT INTO laptopLoggedInLoggedOutInfo(f1,f2,f3,f4,f5,f6,f7) VALUES (?,?,?,?,?,?,?) "
Note that the actual parameter names, e.g. f1,f2,f3, etc. seem not to matter. It is the order in the INSERT statement that matters.
.Prepared = True
.Parameters.Append .CreateParameter("f1", adInteger, adParamInput, , logInId + 1)
.Parameters.Append .CreateParameter("f2", adChar, adParamInput, 20, guardId)
.Parameters.Append .CreateParameter("f3", adChar, adParamInput, 20, studentId)
.Parameters.Append .CreateParameter("f4", adChar, adParamInput, 20, laptopName)
.Parameters.Append .CreateParameter("f5", adChar, adParamInput, 20, laptopBrand)
.Parameters.Append .CreateParameter("f6", adDate, adParamInput, , logInDate)
.Parameters.Append .CreateParameter("f7", adDate, adParamInput, , logInTime)
Don't use a return value in use the following line. And INSERT statement returns no values:
Set rstRecordSet = cmdCommand.Execute
Do this instead:
cmdCommand.Execute
End With
conConnection.Close
You probably don't need to set these variables to Nothing - VB does it for you, anyway. However, if you do, it is generally good practice to do this in reverse order of creation.
Set conConnection = Nothing
Set cmdCommand = Nothing
Set rstRecordSet = Nothing
End Sub
There really isn't much advantage in using ACE formats, you only limit portability. MDBs are almost always a better idea.
You also have a ton of code there for something this minimal. And don't forget to escape the DB path, you can use apostrophes or quotes in the connection string.
Make your "f1" field type IDENTITY ("autonumber").
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim cm As ADODB.Command
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" _
& App.Path & "\Database.accdb';Mode=Read|Write"
Set cm = New ADODB.Command
With cm
.CommandType = adCmdText
'Assume "f1" is type IDENTITY ("Autonumber").
.CommandText = _
"INSERT INTO laptopLoggedInLoggedOutInfo(f2,f3,f4,f5,f6,f7) " _
& "VALUES (?,?,?,?,?,?)"
Set .ActiveConnection = cn
'Seriously? Give those TextBoxes names!
.Execute , _
Array(Text2.Text, Text3.Text, Text4.Text, Text5.Text, Date, Time()), _
adExecuteNoRecords
End With
End Sub
I'am new in programming and my problem is. i have put my ado db connection string into a text box how can i call that text box? i'm creating my program in vb 6 and here's my code.
Private Sub lvButtons_H2_Click()
On Error GoTo errtrap
If Label47.Caption = "True" Then
MsgBox "INITIAL SETTING FOR SHIP ACCOUNT IS BEING PERFORMED", vbOKOnly, "ABORT"
Exit Sub
End If
Dim conas As New ADODB.Connection, rs01 As New ADODB.Recordset, rsx1 As New ADODB.Recordset, RS9 As New ADODB.Recordset
conas.Connectio`enter code here`nString = Text1155.Text
conas.Open
Set RS9 = New ADODB.Recordset
RS9.ActiveConnection = conas
RS9.CursorType = 3
RS9.LockType = 3
RS9.Open ("SELECT * FROM [SHIPACCOUNT].[dbo].[SPARE PART LIST BOND 29 MONTHLY] WHERE NAMECODE = " & Text2.Text & "")
Set DataReport2.DataSource = RS9
DataReport2.Sections("Section2").Controls.item("LABEL12").Caption = Text1.Text
DataReport2.Sections("Section2").Controls.item("LABEL11").Caption = Text3.Text
DataReport2.Sections("Section1").Controls.item("TEXT1").DataField = RS9![PARTSNAME].Name
DataReport2.Sections("Section1").Controls.item("TEXT2").DataField = RS9![Price].Name
DataReport2.Sections("Section1").Controls.item("TEXT3").DataField = RS9![unit].Name
DataReport2.Sections("Section1").Controls.item("TEXT4").DataField = RS9![QTYAPPLY].Name
DataReport2.Sections("Section1").Controls.item("TEXT5").DataField = RS9!QTYAPPROVE.Name
DataReport2.Sections("Section1").Controls.item("TEXT6").DataField = RS9![AMOUNTAPPROVE].Name
DataReport2.Sections("Section1").Controls.item("TEXT7").DataField = RS9![Date].Name
DataReport2.Show 1
Exit Sub
errtrap:
MsgBox Err.Description, vbCritical, "The system encountered an error"
End Sub
You can pass the connection string as parameter to the Connection.Open method
Such as (assuming the name of the textbox is Text1155):
Dim conas As New ADODB.Connection
conas.Open Text1155.Text
(You don't need parenthesis for calling a Sub in vb6)
Your code looks right otherwize...
Application written in VB6. DB is Pervasive v9.5.
Currently works:
Public Sub Save()
if rs.State = adStateOpen Then
rs.AddNew
SetFields rs
rs.Update
End If
end sub
Public Sub SetFields(rs as ADODB.Recordset)
rs!Name = strName
StrToField strReport rs!Report
StrToField strResponse rs!Response
end sub
Public Sub StrToField(ByVal str As String, fld As ADODB.Field)
Dim Data As String
Dim StrSize As Long, CharsRead As Long
' for field of LONVARCHAR type only
If fld.Type = adLongVarChar Then
StrSize = Len(str)
Do While StrSize <> CharsRead
If StrSize - CharsRead < BLOCK_SIZE_LONGVARCHAR Then
Data = Mid(str, CharsRead + 1, StrSize - CharsRead)
CharsRead = StrSize
Else
Data = Mid(str, CharsRead + 1, BLOCK_SIZE_LONGVARCHAR)
CharsRead = CharsRead + BLOCK_SIZE_LONGVARCHAR
End If
fld.AppendChunk Data
Loop
Else
' do something
End If
End Sub
Const BLOCK_SIZE_LONGVARCHAR = 4096
This works fine until my report or response variable is larger than 32000 characters. I receive this error message when rs.update is called:
"[Pervasive][ODBC Client Interface] String length exceeds column length Parameter #15. Data truncated."
Can anyone point me in the right direction or let me know if I am missing something. Pervasive Longvarchar max size should be 2GB.
Thanks,
Graham
This code works form me using PSQL v11 (I don't have v9.5).
Dim conn As New ADODB.Connection
Set conn = New ADODB.Connection
conn.ConnectionString = "demodata"
conn.Open
Dim sql As String
Dim cmd As New ADODB.Command
cmd.ActiveConnection = conn
cmd.CommandText = "insert into lvc (f2) values (?)"
Dim parm As New ADODB.Parameter
parm.Name = "f2"
Dim longstring As String
Open "c:\longdata.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, sNextLine
'do something with it
'add line numbers to it, in this case!
sText = sText & sNextLine
Loop
longstring = sText
parm.Value = longstring
cmd.Parameters.Append cmd.CreateParameter("param1", adLongVarChar, adParamInput, Len(longstring), longstring)
cmd.Execute
conn.Close
MsgBox "done"
Basically, you would use parameterized queries rather than the .AddNew method.