|
Order by goes at the end of the statement.
SQLQuery = "SELECT * FROM Log WHERE Log.ID BETWEEN " & (((sCurrentpage-1)*5)+1) & " AND " & (sCurrentpage*5) & " ORDER BY ID DESC" Michael
I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious.
Vince Lombardi (1913-1970)
|
|
|
|
|
what is the sql statement to get the name of all tables exiting in a database
thank you
|
|
|
|
|
USE db;
GO
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE';
For instance. Presuming, of course, you're talking about MSSQL Server.
--
Henrik Stuart (http://www.unprompted.com/hstuart/)
|
|
|
|
|
SELECT * FROM sysobjects WHERE type = 'U'
D!shan
|
|
|
|
|
Use the INFORMATION_SCHEMA approach that Henrik Stuart described, since MS can and probably will change the structures many of its system tables in future versions of SQL Server.
The results of using the INFORMATION_SCHEMA viewvs are guaranteed to stay the same in all never versions of SQL Server.
Have a look at my latest article about Object Prevalence with Bamboo Prevalence.
|
|
|
|
|
Hello,
I've the following problem to solve: my application store 1.000.000 records on an Oracle DB.
The data are retrieved into a CRecordset class with which the query to the DB is performed. After performing the Open, I've done a while loop until EOF and the result is surprising not 1.000.000 records but something less (275.000).
Consider that I've already checked that in the DB the data are correctly stored and all the queries are corrected 'cause I've performed the same operation directly with a DB tool that gives the good results.
One more hint, if I do a query to count the records in my application the result is good: 1.000.000.
Now my question is: is there any limitation on the data I have to fetch from the DB? Or I'm missing something else?
Thanx for your help!
Fabio
|
|
|
|
|
u want to read 1 million records into memory at one go?
"there is no spoon" biz stuff about me
|
|
|
|
|
Hi everyone,
I would like to know if I can create a new Microsoft Access file using ADO.NET. I have done this in the past using ADOX and it was quite easy.
However, is it possible to do something similar using ADO.NET. I would like to create the database and add tables, reports to it.
Thanks for any help that you might give me.
Xargon
Without struggle, there is no progress
|
|
|
|
|
Hi Xargon. At the moment, your best bet may be to continue using the ADOX library through COM Interop. Here's a link to an article on CodeProject that describes how to use ADOX this way:
http://codeproject.com/books/186100558x_16.asp[^]
|
|
|
|
|
Perfect! Exactly what I needed.
Thanks a ton Mike!
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Is there a way to grant rights to Create and Drop Views but not Tables. All the search I've done seems to indicate that they're both mutually inclusive.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
Support Bone
It's a weird Life
|
|
|
|
|
Books Online[^] seems to indicate that you can grant rights to create tables and views separately. IIRC, you can only Drop an object if you're a member of the db_owner or db_ddladmin roles for the database, or if you own the object. These roles are fixed: you cannot alter the privileges of these roles and you cannot set permissions for user-defined roles.
You can use
GRANT CREATE TABLE TO public to allow all members of the public role to create tables.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Mike Dimmick wrote:
you can only Drop an object if you're a member of the db_owner or db_ddladmin roles for the database
That's what I was afraid of. Thanks, anyway.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
Support Bone
It's a weird Life
|
|
|
|
|
Hi,
im not so good with SQL so pls bear with me if this is too easy... anyways i'd like to display information from two tables "Diagnosis" and "DiagPhar" in a datagrid...my question is how do i code the SQL command text for this...i tried using ways i got from the net but its not working. also how do i setup the datagrid to display the information from two tables.
CODER
|
|
|
|
|
Hi
Try : Select * from Diagnosis,Diagnosis
this brings the two table in one result set and you can show the result set in one grid
|
|
|
|
|
Hi MasudM
thx for the hint. anyways how can i display the data using ONE datagrid?..i would appreciate it if u showed me how...
thx again!
CODER
|
|
|
|
|
Hi
As Mike Said below a full description if need join ! I do not exactly
know what are you after if these two tables have relation you probably need kind of join ! but I can give another hint if you don't know it before !
when you use SqlDataAdapter (or Command) it only turns SqlData to some format that visul Studio can show . then you fill the DataSet
SqlDataAdapter.Fill(DataSet,"TableName"); it brings the sql Data to a format Like Sql But Viewable with visual Sudio Tools !
so you can add two SqlTable to one Table in DataSet then can show that table with a grid .
But Mike's message is very good for joinning Two tables.it works at the SqlServer Level .
|
|
|
|
|
Sounds like you need to JOIN your tables together.
If you want only rows that appear in both tables, use an INNER JOIN. If you want all rows that appear on the left-hand side of the JOIN, with any data appearing on the right-hand side if available, use a LEFT JOIN. Vice-versa, use a RIGHT JOIN. If you want all rows from both tables, regardless of whether corresponding data appears on the other side, use a FULL OUTER JOIN. Finally, if you don't want to use a join condition (the ON clause) and want to output every row of your left-hand table joined to every row of your right-hand table, use a CROSS JOIN.
Example: you have tables OrderLine and Product. An OrderLine maps between an order and the products on that order, and includes the quantity ordered. You want to print an invoice, listing the product details and total prices. You might write something like:
SELECT
OrderLine.Sequence,
OrderLine.Quantity,
Product.ShortDesc,
Product.Price AS ItemPrice,
OrderLine.Quantity * Product.Price AS LinePrice
FROM
OrderLine INNER JOIN Product
ON OrderLine.ProductID = Product.ProductID If, somehow, we had OrderLine rows with ProductID not in the Product table, and we wanted to show those anyway, we would use a LEFT JOIN in the above query. Any fields we refer to from Product, for OrderLine rows with no matching ProductID, will be NULL (e.g. ShortDesc and Price will be NULL for the above query). The INNER JOIN omits these rows.
Note that if there is more than one row on each side that matches the join condition, all those rows will be output, joined to each other. For the sake of argument, let's say that we have two OrderLine rows which refer to ProductID 10, and there are two rows in Product where ProductID is 10 (you would try to avoid this in an ordering system!). Let's give them descriptions ProductA and ProductB. You might get the result
Sequence Quantity ShortDesc ItemPrice LinePrice
-----------------------------------------------
1 2 ProductA 5 10
1 2 ProductB 6 12
2 1 ProductA 5 5
2 1 ProductB 6 6
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
thx Mike n Masud!
with your help, i was able to do what i wanted to. thx again!
CODER
|
|
|
|
|
Is it possible to have a DataView that do not contain all the columns of the corresponding DataTable? If so, how do I do it?
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Hi ...
I am trying to use ADO disconnected recordset to insert data into a sql table. I am using AddNew(vField, vValue) with UpdateBatch(). The code below does not throw any exceptions ... but does not add data to the table.
Any comments are appreciated,
Thanks,
Chris
<br />
<br />
void CTestApp::TestDatabaseUpdateBatch1a(void) <br />
{<br />
int nDataCount = 0; <br />
long nIndex = 0; <br />
long nIndex2 = 0; <br />
<br />
CString csMessage; <br />
CString csErrorMessage;<br />
CString csTemp; <br />
CString csSQL; <br />
<br />
BOOL bIsOpen; <br />
BOOL bIsEmpty; <br />
<br />
long nCount = 0; <br />
int nTemp = 0; <br />
int nLimit = 0; <br />
<br />
int nTempInt = 0; <br />
long nTempLong = 0; <br />
double nTempDouble = 0; <br />
<br />
HRESULT hResult; <br />
<br />
SYSTEMTIME st;<br />
<br />
<br />
int i = 0; <br />
<br />
string strTemp; <br />
<br />
_variant_t sval;<br />
<br />
_variant_t vNull;<br />
vNull.vt = VT_ERROR;<br />
vNull.scode = DISP_E_PARAMNOTFOUND;<br />
<br />
COleSafeArray colesaFieldList;<br />
COleSafeArray colesaDataList;<br />
<br />
vector<COleSafeArray> *pvecDataList;<br />
<br />
pvecDataList = new vector<COleSafeArray>; <br />
<br />
<br />
COleDateTime oledtCurrentDate = COleDateTime::GetCurrentTime();<br />
<br />
COleVariant vCurrentDateTime; <br />
<br />
CMxTextParse *pMxTextParse = NULL; <br />
<br />
CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainWnd(); <br />
CFrameWnd* pChild = pMainFrame->GetActiveFrame();<br />
CTestMeteorlogixView* pView = (CTestMeteorlogixView*)pChild->GetActiveView(); <br />
<br />
pView->WriteLog("Start TestDatabaseUpdateBatch1a."); <br />
pView->WriteLog("Load table using AddNew() and UpdateBatch()."); <br />
<br />
<br />
_ConnectionPtr pConnection = NULL;<br />
_RecordsetPtr pRecordset = NULL;<br />
<br />
try<br />
{<br />
pConnection.CreateInstance(__uuidof(Connection));<br />
<br />
bstr_t bstrConnect("Provider='sqloledb';Data Source='SQLDEV';"<br />
"Initial Catalog='AlphaNumericData';"<br />
"User Id=cmacgowan;Password=cmacgowan");<br />
<br />
pConnection->Open(bstrConnect,"","",adConnectUnspecified);<br />
<br />
pRecordset.CreateInstance(__uuidof(Recordset));<br />
<br />
<br />
csSQL = "SELECT * FROM dbo.AAMacgowanTest WHERE RecordId IS NULL";<br />
<br />
<br />
pRecordset->PutRefActiveConnection(pConnection);<br />
pRecordset->CursorLocation = adUseClient;<br />
<br />
<br />
pRecordset->Open(csSQL.AllocSysString(), vNull, adOpenStatic, adLockOptimistic, -1);<br />
<br />
if(pRecordset->GetState() != adStateClosed)<br />
{<br />
<br />
if((pRecordset->BOF) && (pRecordset->GetadoEOF()))<br />
{<br />
bIsEmpty = false;<br />
}<br />
<br />
<br />
if(pRecordset->GetadoEOF())<br />
{<br />
bIsOpen = false;<br />
}<br />
else<br />
{ <br />
pRecordset->PutRefActiveConnection(NULL);<br />
}<br />
}<br />
<br />
<br />
<br />
pRecordset->PutRefActiveConnection(NULL);<br />
<br />
nCount = 1; <br />
<br />
while(nCount > 0) <br />
{ <br />
nCount--; <br />
<br />
nDataCount = 10; <br />
<br />
if (nDataCount >= 0) <br />
{ <br />
<br />
COleSafeArray warningList;<br />
<br />
VARIANT vFieldList[25]; <br />
VARIANT vValueList[25]; <br />
<br />
int nFieldIndex = 0; <br />
int nValueIndex = 0; <br />
<br />
<br />
vFieldList[nFieldIndex].vt = VT_BSTR;<br />
vFieldList[nFieldIndex].bstrVal = ::SysAllocString(L"Name");<br />
nFieldIndex++;<br />
<br />
vFieldList[nFieldIndex].vt = VT_BSTR;<br />
vFieldList[nFieldIndex].bstrVal = ::SysAllocString(L"Section");<br />
nFieldIndex++;<br />
<br />
vFieldList[nFieldIndex].vt = VT_BSTR;<br />
vFieldList[nFieldIndex].bstrVal = ::SysAllocString(L"Code");<br />
nFieldIndex++;<br />
<br />
vFieldList[nFieldIndex].vt = VT_BSTR;<br />
vFieldList[nFieldIndex].bstrVal = ::SysAllocString(L"Latitude");<br />
nFieldIndex++;<br />
<br />
vFieldList[nFieldIndex].vt = VT_BSTR;<br />
vFieldList[nFieldIndex].bstrVal = ::SysAllocString(L"Longitude");<br />
nFieldIndex++;<br />
<br />
<br />
pView->WriteLog("Set data using AddNew() ..."); <br />
<br />
COleDateTime oledtCurrentDate2 = COleDateTime::GetCurrentTime();<br />
<br />
COleVariant vCurrentDateTime2(oledtCurrentDate2);<br />
<br />
memset(&st, 0, sizeof(SYSTEMTIME));<br />
st.wYear = 2000;<br />
st.wMonth = 1;<br />
st.wDay = 1;<br />
st.wHour = 12;<br />
<br />
for(i = 0; i < 10; i++)<br />
{<br />
<br />
nValueIndex = 0; <br />
vValueList[nValueIndex].vt = VT_BSTR;<br />
vValueList[nValueIndex].bstrVal = ::SysAllocString(L"BLUE");<br />
nValueIndex++;<br />
<br />
vValueList[nValueIndex].vt = VT_BSTR;<br />
vValueList[nValueIndex].bstrVal = ::SysAllocString(L"KSTP");<br />
nValueIndex++;<br />
<br />
vValueList[nValueIndex].vt = VT_I4;<br />
vValueList[nValueIndex].dblVal = 100 + nFieldIndex; <br />
nValueIndex++;<br />
<br />
vValueList[nValueIndex].vt = VT_R8;<br />
vValueList[nValueIndex].dblVal = 11.11 + nFieldIndex; <br />
nValueIndex++;<br />
<br />
vValueList[nValueIndex].vt = VT_R8;<br />
vValueList[nValueIndex].dblVal = 22.22 + nFieldIndex; <br />
nValueIndex++;<br />
<br />
pRecordset->AddNew(vFieldList, vValueList);<br />
}<br />
<br />
<br />
<br />
pView->WriteLog("Call UpdateBatch()."); <br />
<br />
pRecordset->PutRefActiveConnection(pConnection);<br />
<br />
pRecordset->UpdateBatch(adAffectAll);<br />
<br />
pRecordset->Close();<br />
pConnection->Close();<br />
<br />
} <br />
}<br />
}<br />
catch(_com_error *e)<br />
{<br />
CString Error = e->ErrorMessage();<br />
AfxMessageBox(e->ErrorMessage());<br />
pView->WriteLog("Error processing TestDatabase()."); <br />
}<br />
catch(...)<br />
{<br />
csMessage = "Undefined exception handled. Error message details \n\n"; <br />
<br />
hResult = GetAdoErrorMessage(m_pConnection, <br />
&csErrorMessage);<br />
<br />
csMessage += csErrorMessage; <br />
csMessage += "\nmethod: CTestMeteorlogixApp::OnTestDatabaseAdoBulkload()"; <br />
<br />
AfxMessageBox(csMessage);<br />
<br />
}<br />
<br />
csTemp.Format("Last Row %03d DIcastId = %s ", nIndex, strTemp.c_str()); <br />
pView->WriteLog(csTemp); <br />
<br />
pView->WriteLog("End TestDatabaseUpdateBatch1."); <br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
Thanks,
Chris
|
|
|
|
|
Hello to all of you, good code-time for all.
Partners, I'm having a problem and would like to ask for help. Is the following:
I would like to create an App with some reports built-in (no external files, ok?); now, when I create a CrystalReport, assign (in my App) a viewer and later try to execute App, it requests for login, bla, bla, bla (all those things you know) but my database doesn't have any of these, so, what's the matter here? . What is more, have also created a DB with pass and all of these but when filled out what is needed it always says "Logon failed". Suggestions?
Thanx in advance. May schwartz be with U.
Note: If you consider this question should be asked somewhere else, let me know, I'm a newbie here, ok?
|
|
|
|
|
What is the datasource of your report if its dataset, then i think there's no problem.
Or.. Try this one
*************************
private void applyLoginInfo(ReportDocument report){
TableLogOnInfo loginfo = new TableLogOnInfo();
foreach (Table table in report.Database.Tables){
loginfo = table.LogOnInfo;
loginfo.ConnectionInfo.ServerName = database.Server; //Pass the server name
loginfo.ConnectionInfo.DatabaseName = database.Database; //pass the db name
loginfo.ConnectionInfo.UserID = database.UserID; //user id
loginfo.ConnectionInfo.Password = database.Password; //password
table.ApplyLogOnInfo(loginfo);
}
}
I hope this will help you
|
|
|
|
|
I need suggestions.
I am creating a new database for a referral system. I have my main table "tblProviders" along with other 15-20 child tables such as tblTypeFacility, tblLanguges, tblTypePrograms,tblEnvironment...etc.
So, the user will be able to select one or more type of facilities, languagess, etc for each Provider. How can I save this information on the database.
Do I need to normalize every child table.
tblProvider -> tblProviderTypeFacility <-> tblTypeFacility
How this is going to perform and how complicated will be when I create a search for one or more options (type facilities, languages, etc)using asp.
Some one mentioned to do my child table as a lookup table...I am not sure what is a lookup table.
Any suggestion will be great!!
|
|
|
|
|
If you normalise as you suggested then the following SQL-Select statement will find all of the providers who can speak English and French:
select P.ProviderId, P.ProviderName<br />
from Provider P<br />
where P.ProviderId in (select ProviderId from ProviderLangauge where LanguageCode = 'UK')<br />
and P.ProviderId in (select ProviderId from ProviderLanguage where LangauageCode = 'FR')
The performance would depend upon the database that you are using and how many records are in each table (make sure that your development database contains a similar number of records to what you would expect in your live database).
A composite unique index on "ProviderLanguage(LanguageCode, ProviderId)" would be useful for resolving the above query. I would expect a (possibly clustered) primary key on "ProviderLanguage(ProviderId, LanguageCode)" to help your provider-maintenance web page.
I would also strongly recommend that you get yourself a good book on SQL and database design (if you don't already have one). Good knowledge of these two areas tend to lead to much simpler ASP code and much faster performance.
Hope this helps.
Andy
|
|
|
|