|
SQL Server:
SELECT * FROM information_schema.tables WHERe table_type = 'BASE TABLE'
Access: dunno...
|
|
|
|
|
I use this query
if exists(select name from sysdatabases where name='DatabaseName') begin
-- do some stuffs here
end
cheers
|
|
|
|
|
He asked about tables, not databases, so it would be sysobjects where name = 'Foo' and type = 'U', but accessing the sysdatabases/sysobjects/etc tables directly has been depreciated since SQL7. You should use either the metadata functions or the INFORMATION_SCHEMA views instead.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Arjan's answer is also correct, but I prefer:
if objectproperty(object_id('YourTableName'), 'IsTable') = 1 begin
-- do something
end
--
-Blake (com/bcdev/blake)
|
|
|
|
|
I apologised for the mistake. I don't know why 'database' was in my mind then. I also prefer the object_property(object_id()) construct.
Tnx for the correction.
|
|
|
|
|
I'm writting a program that will act as a front end to an access database (although I hope to have it handle other databases eventually) and I've manage to retrive my data using the adapter class to fill a dataset and I've managed to bind the dataset to my form. Now, binding to the textboxes was easy (actually it was quite painful, but now it's easy because I know how to do it), but I'm not sure how to cope with checkboxes that should be set according to a boolean field in the access database. Can anybody tell me the correct way to do this? Also, I haven't even looked at the combo boxes yet, so if anybody has some insight on that they feel like sharing I'd appreciate it.
Cheers
|
|
|
|
|
Never mind. It actually was working all along, the problem was with the data itself.
|
|
|
|
|
_ConnectionPtr m_pConnection;
what does the above statement mean..?
i have to use the above mentioned in my program to get the data from my database..
can some one plzzz explain me on what it actually means...
and i've attached the code also with this query!
does the attached code really help me in making a connection with my database and getting the data from it....???
here's the code i had mentioned:
#include <windows.h>
#include <initguid.h> // Include only once in your application
#include "adoid.h" // ADO GUID's
#include "adoint.h" // ADO Classes, enums, etc.
#include <windows.h>
//#import <msado15.dll> rename("EOF", "adoEOF")
/*In this example, I am using mcb.krz database which is an access database.
The table i do have in example is 'Access' that has two fields,
i.e., Name and HTML, both are Text type fields. Microsoft.Jet.OLEDB.3.51 is OLE_DB provider
for MS Access. To use ADO, you must have OLE-DB provider for that database. */
// Create a Connection object and open it with mcb.krz, an access database
_ConnectionPtr m_pConnection;
BOOL m_bIsConnectionOpen;
// Create an instance of _Connection
HRESULT hr ;
hr = m_pConnection.CreateInstance(__uuidof( Connection) );
if (SUCCEEDED(hr))
{
//Open a connection where database is access database : "d:\mcb.krz"
hr = m_pConnection->Open( _bstr_t(L"Provider=Microsoft.Jet.OLEDB.3.51;
Data Source=d:\\mcb.krz;"), _bstr_t(L""), _bstr_t(L""), adModeUnknown ) ;
//If database opened successfully then set IsConnectionOpen to TRUE
if (SUCCEEDED(hr))
{
m_bIsConnectionOpen = TRUE;
}
}
_RecordsetPtr pRecordset;
// Here I take data from a table called KRUSE1 which has two fields a0, and a1 of TEXT type
_bstr_t bstrQuery("SELECT * FROM Kruse1");
_variant_t vRecsAffected(0L);
try
{
pRecordset = m_pConnection->Execute(bstrQuery, &vRecsAffected,adOptionUnspecified);
if ( !pRecordset->GetadoEOF())
{
int i = 0;
_variant_t vFirstName;
_variant_t vLastName;
while ( !pRecordset->GetadoEOF() )
{
vFirstName = pRecordset->GetCollect(L"a0") ;
vLastName = pRecordset->GetCollect(L"a1") ;
// now you got vFirstName and vLastName values and do whatever u want.
i++;
pRecordset->MoveNext();
}
}
pRecordset->Close();
}
catch( _com_error &e)
{
// get info from _com_error
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
TRACE("%s", e.ErrorMessage());
}
catch(...)
{
TRACE("*** UNHANDELED EXCEPTION ***");
}
ranjani
|
|
|
|
|
ranjjj wrote:
_ConnectionPtr m_pConnection;
That is just declaring an ADO Connection object variable.
ConnectionPtr is a smart pointer for the ADO Connection object interface.
ranjjj wrote:
does the attached code really help me in making a connection with my database and getting the data from it....???
At a quick glance the code seems fine. It should open a connection to an Access database and read all the records from it.
Michael
'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
|
|
|
|
|
_ConnectionPtr m_pConnection;
when executing the file..
i get the error as:
error c2501:_ConnectionPtr missing storage class or type specifier
and
missing identifier ; before 'm_pConnection'
ranjani
|
|
|
|
|
Skip the includes and use the import instead to get the types and remember that the namespace is named ADODB.
|
|
|
|
|
my program should be in c++..
what had namespace to do with it???
what is that ADODB that you have mentioned in oyur program??
and what all includes you have asked me to skip??
ranjani
|
|
|
|
|
If you remove the following includes
<br />
#include "adoid.h"
#include "adoint.h"
and instead use
<br />
#import <X> rename("EOF", "AdoEOF");<br />
you will get all the smartpointers and methodwrappers for ADO.
(Replace the X with the name of the dll/tlb you want to use, i.e. msado15.dll, msado25.tlb and so on,
to see which versions you have installed, have a look at C:\Program Files\Common Files\System\ado)
This is normally imported into the namespace ADODB i.e. ADODB::Connection15Ptr.
To get rid of the namespace, use no_namespace when importing.
|
|
|
|
|
I need someone to fully explain the way to download my sql since I tried and unzipped but probably d-led the wrong one.. Need someone to make a walkthrough with steps starting at mysql.com to the exe. If you would like, you could just e-mail me at snyp_@hotmail.com.
Thankyou,
I would appreciate it and help me develop my sql skills...;P
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
MySQL under Win32 is a little weird and takes after it's Unix heritage quite a bit, so I can understand the confusion.
Here are the basic steps to get started:
- Get the Win32 installer from: http://www.mysql.com/downloads/mysql-4.0.html[^]. The download is a zip file; just unzip the contents into a new directory.
- Run
setup.exe from the unzipped directory. I just accepted the default install path of C:\mysql and used the "Typical" install. - After the installation, you should have a
C:\mysql\bin directory with all the programs associated with MySQL. The easiest way to get started is just to run the winmysqladmin tool. - Right after starting,
winmysqladmin will ask you to create a new user, then will launch the main interface, which will promptly minimize itself to the system tray (!!). To show the interface again, right-click on the icon and select "Show Me". - When WinMySQLAdmin is started, it will automatically start up the MySQL service. You can stop and start the service from the WinMySQLAdmin system tray icon.
- Once the service is started, you can work with the database using
mysql.exe and mysqladmin.exe , which are command-line tools that act just like their Unix counterparts. mysqladmin.exe is used for creating and dropping (deleting) databases, changing passwords, and doing other interesting things to the server. mysql.exe provides a console interface for executing SQL commands.
On install, MySQL provides an empty database called test which you can use as a sandbox for trying out things. To switch to using this database, run mysql.exe (the initial install has no root password, so it should just connect and run) and type use test at the console. Now you're ready to start learning SQL
- Mike
|
|
|
|
|
|
Hi,
I have created a framework in c# which provides a main window with a connection to the database. This window can house various plugins which need to use the database connection, so a 'get' property is provided which returns the SqlConnection.
I would like to avoid the situation where someone can write a plugin which wil close the database connection, thereby preventing the other plugins from using it. It is not expected to be a security feature, more of a convienience to make the system more robust by preventing developers accidently closing the connection.
I do not seem to ba able to specify that the property (or a method for that matter) should return a 'const' method. This doesn't work:
public const SqlConnection Connection
{
get
{
return sqlConnection;
}
}
Any ideas?
David
|
|
|
|
|
I'm not familiar with C#.
This is more of a C# question; why don't you ask on the C# forum[^]?
My feeling is that it's likely to be readonly rather than const , but don't quote me on that.
|
|
|
|
|
Dear All,
Does everyone try to implement application support Unicode. This application use C# and connect Sybase 8.02 via OLE DB Provider for Sybase? If yes, please help me to solve it. The problem is I can not retrieve Unicode data as I entered. It always returns empty string.
Thanks and regards.
|
|
|
|
|
How can I check if a field (for example 'Oldy') exist?
I'm using A set of ADO Classes - version 2.10, but there is no function like GetFieldName(UNIT nIndex). Can any1 help me please?
Love is the law, love under will.
|
|
|
|
|
Recordset.Fields("Oldy") returns a Field object if it exists
|
|
|
|
|
Ok. And how can i get a field name by the index? I would need a function like GetFieldName(UNIT nIndex).
Please help
Love is the law, love under will.
|
|
|
|
|
I use this to grab field names from an ADO recordset for a listctrl:
FieldPtr pFld = NULL;
if(m_pRecordset != NULL ) {
if(m_pRecordset->State == adStateOpen) {
long count = m_pRecordset->Fields->GetCount();
for(long i = 0; i < count; ++i) {
pFld = m_pRecordset->Fields->GetItem(i);
m_DataListCtrl.InsertColumn(i,pFld->Name,LVCFMT_LEFT,100);
In short, the Name is a property of the field item.
|
|
|
|
|
Hi All,
I want to connect to Access Database. I am using Visual Studio.NET beta version. In that I want to use the class System.Data.ADO.ADODataSetCommand. But, when I use this in my code i am getting compile time error as
"the type or namespace name 'ADO' does not exists in the class or namespace 'System.Data' are you missing an Assembly reference.". In my 'References' 'System.Data' is present.
Can anybody tell me what specific assembly reference should I add to get 'ADO' namespace inside 'Data' namespace.
Thanks in advance.
regards,
Pranoti
|
|
|
|
|
I spent most of yesterday being frustrated by ORACLE. Using the ORACLE provided OLE DB driver, I call a stored procedure which doesn't return a recordset. This is done with a parameterised command "{CALL procname(?,?,?)}". So far, so good.
However, if one of the parameters is a BLOB, I have problems. The parameter is an IN BLOB, and I pass it out as an ISequentialStream. Now either it doesn't use the parameter (and it's treated as if I passed in NULL), or it fails with a parameter mismatch. Now you might think that this is all my own fault, but exactly the same code works with a SQL Server SP which takes an IMAGE parameter.
Anyone any ideas on how to resolve this?
Steve S
|
|
|
|