|
Hi everybody,
Once again I need help. I made a COM exposed vb.net lib for an old VB6 app. Which was tested (prior and after COM exposure) using a simple stand-alone .net app with the expected results. Then, used regasm ... to re-generate and register the .tlb file and tested it again using the VB6 app; so far so good.
Copied and registed the new dll and the .tlb files (did registed the .tlb) into two other machines; it all worked as expected. So I said to myself "I am ready to deploy", yeah right!
After following the exact same procedure with tha exact same files in the target machines, all I get is this message: "automation error" (quite explicit, right?)
To rule any missing .net dependencies out, I tested the stand-alone .net app in those machines, and everything works as expected, but can't make the VB6 app work. I ran out of ideas, and of course, bosses want my head!
Can anybody offer any ideas to save my skiny neck? Thank you all so much for your time and interest.
Best regards,
Alex.
|
|
|
|
|
Maybe the vb6 dll does not get registered during the installation.
My signature "sucks" today
|
|
|
|
|
Hi Abhinav,
Thank you for your responce. That was my first thought, no wait, it was not it, my first thought was "what the f..... @!$%%&^*@#$% is going on!" as you very well imagine
I did think of that, so I manually registered the .tlb without positive results.
I can't explain why it works only on some computers. They all (the good ones and the bad ones) have the same .net framework installed, SP, patches, etc. I think it has to do with a VB6 o another COM dll I have not been able to pin-point.
I even used a couple of tools to detect any missing dependecies, both COM and .net, but had no good luck.
|
|
|
|
|
alexvw wrote: Then, used regasm
You'd additionally need to run "regsvr32" for any OLE-controls (ActiveX components and the likes).
Additionally, you might want to check what version of MDAC is installed.
I are Troll
|
|
|
|
|
Good day Eddy,
Thank you for your suggestion, I shall look into it! and will let you know the result.
Best regards.
|
|
|
|
|
What's the VB6 counterpart of the following codes?
To insert a record in database with command object parameters:
dim strSql as string
strSql = "Insert Into tblEmployees (EmpName,DeptartmentID,JoinDate) Values ('" & _
txtName.Text & "'," & Val(cboDepartment.Value) & ",@JoinDate)"
com = CreateCommand(strSql)
com.Parameters.Add(New SqlParameter("@JoinDate", SqlDbType.DateTime))
If (dtpJoinDate.Checked) Then
com.Parameters("@JoinDate").Value = Convert.ToDateTime(dtpJoinDate.Value)
Else
com.Parameters("@JoinDate").Value = DBNull.Value
End If
If com.ExecuteNonQuery = 1 Then
MsgBox("Record saved.")
End If
To obtain a record from database:
Dim drd As SqlDataReader
strSql = "Select EmpName,DeptID,JoinDate From tblEmployees Where EmpID=1001"
drd = CreateReader(strSql)
If drd.Read Then
txtName.Text = drd("EmpName")
cboDepartment.Value = drd("DepartmentID")
If IsDBNull(drd("JoinDate")) Then
dtpJoinDate.ResetText()
dtpJoinDate.Checked = False
Else
dtpJoinDate.Value = drd("JoinDate")
End If
End If
drd.Close()
|
|
|
|
|
See here.
My signature "sucks" today
|
|
|
|
|
You need to include references to SQL in VB6. But I doubt if it is supported..
|
|
|
|
|
It's supported 
|
|
|
|
|
Hi,
You can find an example on VB6 and ADO over here[^].
I are Troll
|
|
|
|
|
Sorry for not to be specific. I want to get the vb6 counterpart for passing dbnull value to database and getting the datareader object (recordset object in case of vb6) and check for dbnull value of one or all of its fields. The following blocks to be specific:
com.Parameters.Add(New SqlParameter("@JoinDate", SqlDbType.DateTime))
If (dtpJoinDate.Checked) Then
com.Parameters("@JoinDate").Value = Convert.ToDateTime(dtpJoinDate.Value)
Else
com.Parameters("@JoinDate").Value = DBNull.Value
End If
If IsDBNull(drd("JoinDate")) Then
'statements.......
'....................
Else
'statements.......
'....................
End If
I want the vb6 counterpart of the upper mentioned blocks (specially the bolded lines) in terms of recordset objects. I'm acquainted in handling recordset objects. Hope this time I'm more specific.
|
|
|
|
|
That would be something along these lines;
Dim MyParam As ADODB.Parameter
If ... Then
Set MyParam = MyCom.CreateParameter("JoinDate", adDate, adParamInput, dtpMyCalendar.value)
Else
Set MyParam = MyCom.CreateParameter("JoinDate", adDate, adParamInput, Noting)
End If
MyCom.Parameters.Append MyPara
Set MyRecordSet = MyCom.Execute
If IsNull(MyRecordSet(k).Value) Then
I are Troll
|
|
|
|
|
 Thanks Eddy, implemented your idea. My problem is almost solved except a small bug. I have a data entry form with certain fields among which is a datetimepicker. The idea is while inserting or updating records through that form the application will first check whether the datetimepicker is checked. If yes then it'll pass the value of datetimepicker to the command parameter or else it'll pass null value to the command parameter. The corresponding database table column for the datetimepicker field has smalldatetime data type. First take a look into my code:
Private con As ADODB.Connection
Private Sub cmdOk_Click()
Dim com As ADODB.Command
Dim lngRetVal As Long
On Error GoTo ErrorHandler
'If Not Validate Then Exit Sub
If strItemID = Empty Then
strSql = "Insert Into tblItemList (ItemID,Item,CategoryID,Quantity,Rate,Half,HalfQuantity,HalfRate,ExpiryDate) Values ('" & _
ReplaceQuote(txtItemID.Text) & "','" & ReplaceQuote(txtItem.Text) & "'," & SetDataCombo(cboCategory) & ",'" & _
ReplaceQuote(txtQuantity.Text) & "'," & Val(txtRate.Text) & "," & IIf(chkHalfAvailable.Value, 1, 0) & ",'" & _
ReplaceQuote(txtHalfQuantity.Text) & "'," & Val(txtHalfRate.Text) & ",?)"
Else
strSql = "Update tblItemList Set ItemID='" & ReplaceQuote(txtItemID.Text) & "',Item='" & ReplaceQuote(txtItem.Text) & "'," & _
"CategoryID=" & SetDataCombo(cboCategory) & ",Quantity='" & ReplaceQuote(txtQuantity.Text) & "',Rate=" & _
Val(txtRate.Text) & ",Half=" & IIf(chkHalfAvailable.Value, 1, 0) & ",HalfQuantity='" & ReplaceQuote(txtHalfQuantity.Text) & "'," & _
"HalfRate=" & Val(txtHalfRate.Text) & ",ExpiryDate=?" & " Where ItemID='" & strItemID & "'"
End If
Set com = CreateCommand(strSql)
com.Parameters.Append com.CreateParameter("ExpiryDate", adDate, adParamInput)
If Not IsNull(dtpExpiry.Value) Then
com("ExpiryDate") = CDate(dtpExpiry.Value)
Else
'Using Nothing instead of Null in the following line generates an error- ‘Application uses a value of the wrong type for the current operation’.
com("ExpiryDate") = Null
End If
com.Execute lngRetVal, adCmdText, adExecuteNoRecords
If lngRetVal = 1 Then
Msgbox "Record saved."
Unload Me
End If
CloseConnection
strSql = Empty
Exit Sub
ErrorHandler:
CloseConnection
strSql = Empty
MsgBox "The following error has occurred:" & vbCrLf & Err.Description, vbCritical, "Error"
End Sub
Private Sub OpenConnection()
If con Is Nothing Then
Set con = New ADODB.Connection
con.Open "Provider=SQLOLEDB.1;Data Source=MyServer;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TestDB"
End If
End Sub
Private Sub CloseConnection()
If Not con Is Nothing And con.State = adStateOpen Then
con.Close
Set con = Nothing
End If
End Sub
Private Function CreateCommand(strQuery As String) As ADODB.Command
Dim com As New ADODB.Command
OpenConnection
com.ActiveConnection = con
com.CommandText = strQuery
Set CreateCommand = com
End Function
Now about the problem. When I try to save, the system throws an error- 'The conversion from datetime data type to smalldatetime data type resulted in a smalldatetime overflow error'.
When I change the database table column data type to datetime and try to save the data from the form, it saves the default datetime value i.e. 31/12/1899 12:00:00 AM irrespective of what I pass through the parameter. Please help me sort out this problem, preferrably with the smalldatetime data type instead of the datetime as my application mainly deals with it. 
|
|
|
|
|
Hi,
Good work, seems you're almost there
What type of database are you using? You might be able to pass a DateTime and to convert that to a SmallDateTime in the SQL-statement itself. That would look something like this for the update-part of the statement;
"HalfRate=" & Val(txtHalfRate.Text) &
",ExpiryDate=convert(smalldatetime,?) " &
" Where ItemID='" & strItemID & "'"
Alternative, you could pass a DateTime to a stored procedure and to convert it to a SmallDateTime within that stored procedure. As a last resort you could pass them as a constant datetime-value, formatting the string by hand. That would resemble this;
"HalfRate=" & Val(txtHalfRate.Text) &
",ExpiryDate=#" & Format(CDate(dtpExpiry.Value), "mm/dd/yy") & "# " &
" Where ItemID='" & strItemID & "'"
You're already using strings to add the other values into the command-object; those would best be parameter-objects (also using CreateParameter ), even though that adds to the amount of work. It will make the code easier to maintain in the future.
I are Troll
|
|
|
|
|
I've created a drop down "file" tab and I've added a close file tab the code below is the code I was using but I am getting an error saying Property access must assign to the property or use its value. Can anyone please show me where I've gone wrong in this code. Thank you in advance.
Private Sub CloseTabToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseTabToolStripMenuItem.Click
Dim i As Integer = 1
If Not TabControl1.TabPages.Count = 1 Then
TabControl1.TabPages.RemoveAt(TabControl1.SelectedIndex)
TabControl1.SelectedTab(TabControl1.TabPages.Count - 1)
i = i - 1
End If
End Sub
End Class
|
|
|
|
|
What is this line supposed to do?
TabControl1.SelectedTab(TabControl1.TabPages.Count - 1)
If you are trying to select a tab, I think you have to use this:
TabControl1.SelectTab(TabControl1.TabPages.Count - 1)
|
|
|
|
|
It is meant to close the current open tab
|
|
|
|
|
when I double click on the error it says
TabControl1.SelectedTab(TabControl1.TabPages.Count - 1)
is the part of the code that has the error, it just keeps saying "Property access must assign to the property or use its value"
|
|
|
|
|
John McMahon wrote: Property access must assign to the property or use its value
That tells me that perhaps the code should read something like:
TabControl1.SelectedTab = TabControl1.TabPages.Count - 1
?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
I changed Selectedtab to selecttab as you said and it does exactly as I wanted now Thank you so much.
|
|
|
|
|
Hello everyone,
I've got a datagridview in a control which i populate programmatically using values retrieved from a database. Mostly it is fine, however when I set the vale of the cell to be a date i.e "2010-06-10" it transforms it into "10/06/2010 00:00:00". Oh and the type on the database is date...I'm guessing this is what vb is using as the cells format....
I don't mind the date switching around but the addition of the 00:00:00 looks stupid. I know it's probably very simple but I can't find the solution anywhere.
thanks in advance
Chris
modified on Friday, June 11, 2010 11:11 AM
|
|
|
|
|
How are you populating the DataGrid? Are you using a DataSet, DataTable or are you populating manually with a DataReader ? The answer to that question would enable someone to answer properly.
|
|
|
|
|
Hi,
sorry I'm doing it manually using a datareader:
While drgetcusfile.Read()
Dim count As Integer = fieldnostart
Dim rowcount As Integer = 0
grid.Columns.Add("Property", "Property")
grid.Columns.Add("Value", "Value")
While count <= fieldnoend
grid.Rows.Add()
grid.Item(0, rowcount).Value = rows(rowcount)
grid.Item(1, rowcount).Value = drgetcusfile.Item(count)
count += 1
rowcount += 1
End While
the datareader returns 1 row of various different types of data.
thanks,
Chris
|
|
|
|
|
I think in that case you will need to specifically test whether the value is a date using something like this :
While count <= fieldnoend
grid.Rows.Add()
grid.Item(0, rowcount).Value = rows(rowcount)
if drgetcustfile.Item(count).GetType.ToString = "System.DateTime" Then
grid.Item(1, rowcount).Value = Format(drgetcusfile.Item(count),"short date")
Else
grid.Item(1, rowcount).Value = drgetcusfile.Item(count)
End If
End While
This is just off the top of my head. Hope it Helps
Happy Coding
|
|
|
|
|
hi,
thanks for that, I think it would work.....
I figured another way around it when you asked about the method i was using to get the data:
While count <= fieldnoend
grid.Rows.Add()
grid.Item(0, rowcount).Value = rows(rowcount)
Try
grid.Item(1, rowcount).Value = drgetcusfile.GetString(count)
grid.Item(1, rowcount).Value = DateTime.ParseExact(grid.Item(1, rowcount).Value, "yyyy-MM-dd", Nothing).ToShortDateString()
Catch ex As Exception
End Try
count += 1
rowcount += 1
End While
the Datareader.GetString method is what I was looking for to get the exact string on the database, so I can try to parse it into a decent looking date.
Chris
|
|
|
|
|