|
In this example I am using the datadapter, as you can bind the whole resultset to the grid in one command, with the datareader you have to loop through the resultset.
Dim oConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection()
Dim oCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand()
Dim oDataTableResources As Data.DataTable = New Data.DataTable()
Dim oDataTableSites As Data.DataTable = New Data.DataTable()
Dim oDataAdapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter()
Dim sSiteName As String
Dim sResourceName As String
Const iDayLength As Integer = 86400
sSQL = "Select * from Category"
gsConnectString = " Initial Catalog=" & UCase(Trim(Me.txtDB.Text)) & _
";Data Source=" & UCase(Trim(Me.txtSVR.Text)) & _
";User ID=" & UCase(Trim(Me.txtUID.Text)) & _
";Password=" & Trim(Me.txtPWD.Text) & ";"
oConnection.ConnectionString = gsConnectString
Try
oConnection.Open()
Catch o As System.Exception
MsgBox(o.Message, MsgBoxStyle.Critical, gsMessageBoxHeader)
Me.Cursor = Cursors.Default
Exit Sub
End Try
Try
oCommand.Connection = oConnection
oCommand.CommandText = sSQL
oDataAdapter.SelectCommand = oCommand
'fill the data adapter
oDataAdapter.Fill(oDataTableResources)
'bind to the datagrid
dbgrdDataGrid.DataSource = oDataTableResources
dbgrdDataGrid.ParentRowsVisible = False
Catch o As System.Exception
MsgBox(o.Message)
Me.Cursor = Cursors.Default
End Try
I do not have any code of getting a specific cell from the grid. I am sure you will be able to find samples on the web.
YASP
|
|
|
|
|
runtime error "class does not support..."
"Class does not support automation or does not support expected interface"
I've double checked that the correct dll is being referenced, so thats not the problem, plus it works fine on my machine. On a win98 and a win2k that I've tried so far I get the above error.
Any ideas? I installed the dll with PDW so all files should be present on the users machines.....
Thanks,
ns
|
|
|
|
|
hmmm.... Is the .dll registered, that is different than just being present.
If not try this at the command prompt:
C:\[location of .dll]\ <code>regsvr32 myComponent.dll</code>
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
It is registered because I'm building it on my machine locally...
Thanks,
ns
|
|
|
|
|
ns wrote:
"Class does not support automation or does not support expected interface"
Bizarrely, this usually means that the build version of the DLL is different from the build version expected by the program.
If you have a test program for a DLL that you've rebuilt, you need to rebuild the program too.
Paul
|
|
|
|
|
Really I am rebuilding each time, and I know its connnected to the new dll because I'll put in identifying msgboxes in the new dll. But thanks for the answer....
Thanks,
ns
|
|
|
|
|
No problem.
I still think you'll find it's something along these lines. I had a bizarre fault once with an InstallShield Automation DLL.
I wrote a couple of programs using v7.0.1. When I upgraded to v7.0.2, the austomation programs stopped working; the two DLLs were byte-for-byte identical except for the version number. I tried rebuilding with no luck.
Eventually, I switched the DLL back to v7.0.1 and everything worked fine.
When I later upgraded to 7.0.3, the programs rebuilt and worked fine.
Go figure.
Paul
|
|
|
|
|
This is a dll that I wrote though. It gets into the dll, executes one step of the loop, then the error pops up. I have a progress bar in the calling app thats getting updated bythe dll, so thats why I know its gone one step...because the bar has one little block in it...
Thanks,
ns
|
|
|
|
|
Very bizarre. Sorry, you're out of my depth
Paul
|
|
|
|
|
see my latest post --maybe it'll be clear to you exactly whats happening...
Thanks,
ns
|
|
|
|
|
Dim Conn1 As New ADODB.Connection
Dim Cmd1 As New ADODB.Command
' Dim Errs1 As Errors
Dim Rs1 As New ADODB.Recordset
Dim adoField As ADODB.Field
MsgBox "in pop"
AccessConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + dataBaseName
Conn1.ConnectionString = AccessConnect
Conn1.Open
MsgBox 1 'fires
Cmd1.ActiveConnection = Conn1
MsgBox 2 'doesnt fire
Cmd1.CommandText = "SELECT * FROM tblTest"
I packaged the dll with PDW so I dont know whats missing....
My references are ado 2.7 library, and MMS extension 2.7 for dds and security. These went along in the cab I think (I saw the adox in PDW list)
Thanks,
ns
|
|
|
|
|
No idea.
I would have done this differently:
Dim Cmd1 As New ADODB.Command
AccessConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + dataBaseName
Cmd1.ActiveConnection = AccessConnect
Cmd1.CommandText = "SELECT * FROM tblTest"
' blah blah blah
Set Cmd1.ActiveConnection = Nothing purely because I'm lazy and this does all the work (opening connections) for you. However, as far as I can see, you should be able to do it that way.
Here's a strange idea... have you tried
Set Conn1.ConnectionString = AccessConnect
?
Paul
|
|
|
|
|
I had referenced the ado 2.7 library . My target had 2.5 on it. PDW didnt update the mdac on the target. So, I built the dll with the 2.5 ADO library instead and it works. Only problem is that PDW while installing the dll told me there was an error registering msado25.tlb, which is use by other parts of my program so I have to check and see if they work...
Thanks so much for your input.
Thanks,
ns
|
|
|
|
|
HA! Told you it was DLL versioning
Seriously though, I can see why that was confusing. I'd have expected it to fall on the Connection object.
Glad you got there.
Paul
|
|
|
|
|
I need the form to .show and not .hide, but the user shouldnt bec able to see it. How do I position it off the screen? In code or manually or both?
Thanks,
ns
|
|
|
|
|
Are you only trying to get the form to call Form_Activate() and not be visible?
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
No. I will trigger the click event of a button on the form - thats my only avenue of siganlling VB remotely to do something. So the form and button should be off in the ozone somewhere...if I .hide it the click wont happen..
Thanks,
ns
|
|
|
|
|
How do you get the handle of say a button on a VB form once you have its handle by locating it on the desktop with its caption?
Thanks,
ns
|
|
|
|
|
Hi !
Using VB6, in a standard EXE app, I'm trying to add in a collection elements of my own type :
<br />
Option Explicit<br />
<br />
Private m_colMyCol As Collection<br />
<br />
Private Type MyType<br />
lLong As Long<br />
iInteger As Integer<br />
sString As String<br />
End Type<br />
<br />
Private Sub Form_Load()<br />
Dim l_lRec As MyType<br />
Set m_colMyCol = New Collection<br />
<br />
l_lRec.iInteger = 1<br />
l_lRec.lLong = 10<br />
l_lRec.sString = "Hello"<br />
m_colMyCol.Add l_lRec<br />
<br />
MsgBox m_colMyCol.Count<br />
End Sub<br />
When I run this sample code, I get this error :
Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types
I tried to put the type declaration as Public in a module, but I still get the same message.
Anyone got an idea what I'm doing wrong ?
Thanks !
Jerome
|
|
|
|
|
Yes, it can't be done. The only way I was able to do this was to Create a simple Class module and store the Class Objects within the Collection.
1.) Create a Class in your App.
2.) Create the Properties
Public ID As Long
Public intCounter As Integer
Public Key As String
That's it! Just create new instances of the class and store them in the Collection.
|
|
|
|
|
How to set VB up to recv this user defined message?
I need to send info to a VB dll from a VC client with sendmessage with a message I've defined myself (WM_USER + something). What do I need to do in VB to let it know how to respond to the message?
If suppose I had a form with a button in my dll, how would I get its handle so that my C dll can send a message to its click event?
Thanks,
ns
|
|
|
|
|
I hope there are still some VB6 people out there to help me. I am quite new to VB and so perhaps my problem won't prove to be too hard...
Anyway, I have already loaded images (.jpgs) into an Image control which is nested inside a PictureBox. The PictureBox along with a couple of scrollbars is acting as a window into the Image. The Image control has Stretch=True so that whatever size I make the control the loaded image will fit that size for me, ie. I can also zoom.
Now, what I want to do is using the image as a background, allow the user to draw simple graphics in the foreground.
I prototyped the drawing separately in a PictureBox but then I found all the draw methods are not available in an Image control!
The image & drawing does work together in a PictureBox instead, but then there is no Stretch equivalent, so zooming is not possible.
I also thought of using both an Image control for the background (with Stretch=True) and a PictureBox for the drawing, with its background set to invisible (to overlay the two nested controls). But the background does not allow this.
So, now I have run out of ideas!!
Please help...
Bodie
|
|
|
|
|
can anybody please tell me how to bind data with textbox after executing search query thru code?
here is what i did to execute select query thru code and now i dont know how to display those results ( how to bind them to textbox)
Dim str, str2 As String
str = "SELECT completelist.* FROM completelist, shortlist WHERE (@keycode=completelist.keycode) And (@startframe=completelist.frame) And (@stoffset=completelist.offset)"
str2 = str & "UNION SELECT completelist.* FROM completelist, shortlist WHERE(@keycode=completelist.keycode) And (@endframe=completelist.frame) And (@enoffset=completelist.offset)"
Dim selcom As New OleDbCommand(str2, OleDbConnection1)
OleDbDataAdapter1.SelectCommand = selcom
OleDbDataAdapter1.SelectCommand.Parameters.Add(New OleDbParameter("@keycode", OleDbType.Char, 10))
OleDbDataAdapter1.SelectCommand.Parameters("@keycode").Value = keycode.Text
OleDbDataAdapter1.SelectCommand.Parameters.Add(New OleDbParameter("@startframe", OleDbType.Integer, 4))
OleDbDataAdapter1.SelectCommand.Parameters("@startframe").Value = startframe.Text
OleDbDataAdapter1.SelectCommand.Parameters.Add(New OleDbParameter("@stoffset", OleDbType.Integer, 2))
OleDbDataAdapter1.SelectCommand.Parameters("@stoffset").Value = stoffset.Text
OleDbDataAdapter1.SelectCommand.Parameters.Add(New OleDbParameter("@endframe", OleDbType.Integer, 4))
OleDbDataAdapter1.SelectCommand.Parameters("@endframe").Value = endframe.Text
OleDbDataAdapter1.SelectCommand.Parameters.Add(New OleDbParameter("@enoffset", OleDbType.Integer, 2))
OleDbDataAdapter1.SelectCommand.Parameters("@enoffset").Value = enoffset.Text
OleDbConnection1.Open()
OleDbDataAdapter1.SelectCommand.ExecuteNonQuery()
OleDbConnection1.Close()
OleDbDataAdapter1.Fill(DataSet1)
please help me getting the results from the query ..!!
|
|
|
|
|
Hi There
If you are going to use the resultset for display purpose only, it is better to use the datareader to retrieve the data as in the following piece of code.
The code shows how to read the sql results into a combo box, but you would do the same for a text box (given that you only return one row from the db)
I think it would also be easier to read the parameters from the input text boxes as you build up the sql string, ie:
sSQl = "select * from publishers where name = " + txtName.text + " and date ........" etc
Private Sub LoadInitData()
Dim sConnect As String
Dim sCategory As String
Dim sType As String
Dim sPrinter As String
Dim odrCategory As OleDb.OleDbDataReader
Dim odrType As OleDb.OleDbDataReader
Dim odrPrinter As OleDb.OleDbDataReader
Dim oConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection()
Dim oCommand As OleDb.OleDbCommand = New OleDb.OleDbCommand()
Dim sDBPath As String
sDBPath = Application.StartupPath
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBPath & "\Inks.MDB"
sCategory = "SELECT CATEGORY.CATEGORY FROM CATEGORY ORDER BY CATEGORY.CATEGORY"
Try
oConnection.ConnectionString = sConnect
oConnection.Open()
'get categories
oCommand.CommandText = sCategory
oCommand.Connection = oConnection
odrCategory = oCommand.ExecuteReader
While odrCategory.Read
Me.cmbCategory.Items.Add(odrCategory.GetString(0))
End While
If cmbCategory.Items.Count > 0 Then
cmbCategory.SelectedIndex = 0
End If
odrCategory.Close()
oConnection.Close()
Catch o As System.Exception
MsgBox(o.Message)
Exit Sub
End Try
End Sub
YASP
|
|
|
|
|
HELP a brother (fellow developer) out!
Apparently, Coyote Software doesn't produce ActiveX controls anymore. They also do not respond to emails concerning ActiveX controls either.
I'm looking for the trial version of their Multi-Column ComboBox ActiveX control.
The file name is "combodemo.zip"
Does anyone, by any chance, know of where I can grab a copy?
- (distraught)
|
|
|
|