|
Hi,
I don't think you can do that in SQL, you cannot use a variable as the table name in the "create table" statement.
I don't think it's a good idea to do that anyway. You should use just create another table and create a foreign key in that table referencing the autonumber of TABLEOFTABLES, that should solve your problem.
Pyt.
|
|
|
|
|
You can create table programmatically using ADOX (ADO extensions to manage database dictionary). However, like others said, it's not very good idea to create a table per city. Basically it's bad design. Why can't you store information for all cities in a single table and use indexes to retrieve data that belongs to each city. Believe me, it's so much easier.
Vagif Abilov
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|
|
<<why can't="" you="" store="" information="" for="" all="" cities="" in="" a="" single="" table="" and="" use="" indexes="" to="" retrieve="" data="" that="" belongs="" each="" city.="" believe="" me,="" it's="" so="" much="" easier.="">>
Believe me, I wish I could for this project!! I have to use one table per city because the device I'm programming (Pocket PC - 2002) using AppForge 3.1 doesn't do SQL statements all that well. Using a 'select * from CITIES' won't work because AppForge (reportedly) only returns EXACT matchs. Finding similarities (LIKE) is a NO-GO.
1) I can't create new tables based upon the results from a query.
2) I can't open and close DBs or tables within a DB because of a memory leak created BY AppForge (It's written in their documentation) - not my code.
3) Management has just set fire to the hoop they want me to jump through.
On the other hand, I'm not a VB programmer, per se, although I've been programming VB on a "professional level" (scary, huh?) for the better part of six months. Being a C/VC++ programmer, one could imagine my disparity toward programming in VB. Not that I don't want to learn VB but I should at least learn before being forced to program in it.
Sorry for the rant. This 'problem' has been wieghing on my concious for the better part of this development cycle.
|
|
|
|
|
Hi,
I have converted a delimited text file to a DataTable and added to a new DataSet (using VB and ADO.NET). I will add more than 1 table to this DataSet.
Then my next task is to convert these tables into serveral xml files.
For example, for the Category Table, I will have to make an xml file which contain datas where category num < 1000, and another xml file which contain datas where category num > 1000. However, since the WriteXml only belongs to the DataSet Object, but not the DataTable object, how do I do this????? ??????
Please help meeeee!!!!
Thanks a million!
Karen
|
|
|
|
|
Go through all rows in the table in a loop and then check if num < 1000.
Then store each row in a new table (add new DataRow to a DataTable) and assign that table to a DataSet and call WriteXml....
Do you understand?
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Hey Thomas,
I am not too sure of MySQL Administration however with some use of MySQL, I think MySQL needs to be informed of the IP Addresses or hosts that need to be connected. If the connecting php and the mysql resides on the same host, then you can use
localhost
instead, since localhost can always connect.
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
Hi there,
I am using OleDB to connect to an IBMDB2 database on an AIX Server on Rs/6000 and also to a Linux based IBMDB2 database.
All is okay but when there is a duplicate record insertion, which has to be handled by a try catch block and return to the calling file, IIS/ASP.NET Worker Process fails miserably with a error message called
Server Application Unavailable. Event Viewer logs a message
aspnet_wp process stopped unexpectedly.
When I tried to run the query via Console Application, the try catch block is not able to handle this type of SQL Error alone. Instead it raises an Exception
System.ExecutionEngineException
The problem does not seem to be with the application, since it can handle any SQL statement failures and can gracefully return the error message except for the the dreaded Primary Key/Unique Key violation exception.
A Free Utility for SQL/OlEDB called QueryExpress from http://www.albahari.com/ also fails and crashes with the abovesaid exception.
We doubt whether the OLEDBDriver (Provider=IBMDADB2) is the culprit since if we use Microsoft ODBC.NET (Driver=IBM DB2 ODBC Driver), the above exception is gracefully handled.
While anything via IBM OleDb Driver fails, IBM DB2 Command Center is able to report the error gracefully along with some SQLState etc.
But my question is there any other OLEDB providers for DB2 database from Microsoft or any other vendor?
Thanks in advance...
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
I'm a newbie with SQL so please take it easy on me...
Anyways...
I have 2 tables
clients ( email, name, phone, address, agencyid )
agency ( agencyid, email, name, phone, address, website )
I need to pull all the agency records out and determine if they have clients/members...???
How would I do this...i'm so lost???
Currently I have something like:
SELECT agency, clients WHERE agency.agencyid = clients.agencyid AND this is where i'm lost
Is there anyway inside the SQL statement I can determine if an agency has no members...? This is what I need returned...agencies with no members...???
Do I have to use a for loop?
I'm using mySQL and PHP BTW
$query = "SELECT * agency";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
for($i=0; $i<mysql_num_rows($result); $i++){
$clientResult = mysql_query("SELECT * clients WHERE clients.agencyid = $row[$i].agencyid");
if(mysql_num_rows($clientResult) == 0)
}
Do I have to do it like the above or can I accomplish this from ONE SQL statement...? Or Am I doing it all wrong...?
Thanx!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hockey wrote:
Is there anyway inside the SQL statement I can determine if an agency has no members...? This is what I need returned...agencies with no members...???
The in statement in SQL is brilliant. Basically in your case you need to do this: select * from agency where Not AgencyID in (select AgencyID from Clients)
That should return all agency rows which do not occur in clients.
in can be used many ways. For instance if you have a pre-defined list of values to check for you can do: select * from agency where Not AgencyID in (1, 2, 3, 4)
Paul Watson Bluegrass Cape Town, South Africa Ray Cassick wrote: Well I am not female, not gay and I am not Paul Watson
|
|
|
|
|
I've actually used the in statement before, but only like in your second example...
Anyways, I appreciate the help Paul...I was getting pretty desperate...
One question? I just read a little more on the subject and it appears I could accomplish something very similar using a left join...???
I will have to read up on this appraoch more, but which would be more efficient...?
Thanx again
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hey Paul, i'm getting the following error, you wouldn't care to help me figure out why...?
<br />
SQL-query : <br />
<br />
SELECT * FROM agency WHERE NOT agencyid IN (SELECT agencyid FROM clients) LIMIT 0, 30<br />
<br />
MySQL said: <br />
<br />
<br />
You have an error in your SQL syntax near 'SELECT agencyid FROM clients) LIMIT 0, 30' at line 1<br />
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hockey wrote:
MySQL
Doh, I just assumed you meant Microsoft SQL Server. I have about 2 hours experience with MySQL and most of it was spent cursing
There are some differences between the TSQL that MS SQL Server uses and the SQL that MySQL uses.
*the following is pure guessing so I could be utterly wrong*
If I had to guess, the error seems to be saying that a in statement has a maximum of 30 returnable rows. There might be a setting in MySQL for this.
If none of that works then in answer to your other question about rather using a join..
SELECT
Clients.ClientID,
Clients.AgencyID AS ClientAgencyID,
Agency.AgencyID,
Agency.Name AS AgencyName
FROM
Clients FULL OUTER JOIN
Agency ON Clients.AgencyID = Agency.AgencyID
WHERE (Clients.ClientID IS NULL)
Sorry but I can't test it against a MySQL box so I do not know if it works on MySQL, works on MSSQL though.
As for performance I am no DBA so I really could not tell you which is faster.
Paul Watson Bluegrass Cape Town, South Africa Ray Cassick wrote: Well I am not female, not gay and I am not Paul Watson
|
|
|
|
|
MySQL doesn't support subSELECTs at all. You must replace the nested query, see the MySQL manual.
|
|
|
|
|
Brutal...
I ended up using multiple queries inside a for loop...proabbly not the MOST elegant solution, but it works...
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hello,
I want to use the SELECT some recordsets in an XML format (using the SQL Server 2000 features). I am using Carlos Antollini classes that wrap the ADO database clases. I am declaring a CADORecordset object, open it and use GetFieldValue (0, var), where var is a _variant_t object.
Its type is VT_ARRAY | VT_UI1 (this means an array of bytes, rights?). The parray member looks like this:
cDims = 0x0001;
fFeatures = 0x0080;
cbElements = 0x00000001;
cLocks = 0x0;
pvData = 0xsmth;
Dumping my array of bytes into a file looks awful. However, looking at the code the array looks like an array of BSTRs, but is not the XML encoded data I am expecting.
Can anyone help?
Thanks.
Best regards,
Alexandru Savescu
Best regards,
Alexandru Savescu
|
|
|
|
|
I am saving an ADO recordset as an XML. It works fine. However I do not want to save into a file, I would like to save it into a stream, a CString, ostream etc. Anyone have an idea?
Thanks!
Best regards,
Alexandru Savescu
|
|
|
|
|
You can pass a Stream object to the Save method of the recordset. For example, in IIS 5 you can pass in the Response object, and the XML will be sent straight to the browser.
|
|
|
|
|
I am trying to retrieve data using datasets in C#. However when i use the select command "SELECT * from Some_table". if there is a field which has a null in it, when the dataset returns the XML, the field is not present. When I put data in this column, the field is then present in the returned XML.
Is there a setting for enabling null fields in the results.
Here is the code
<code>SqlCommand sqlCommand = new SqlCommand("Select * from MyTable",sqlConnection1);
SqlDataAdapter custDA = new SqlDataAdapter();
custDA.SelectCommand = sqlCommand;
sqlConnection1.Open();
DataSet custDS = new DataSet();
custDA.Fill(custDS,strName);
sqlConnection1.Close();
strRet = custDS.GetXml();</code>
|
|
|
|
|
May I ask why it bothers you this? The XML file is smaller.
Best regards,
Alexandru Savescu
|
|
|
|
|
This might help[^], search for "drops column fields with null values" to get to the relevant paragraph.
Paul Watson Bluegrass Cape Town, South Africa Ray Cassick wrote: Well I am not female, not gay and I am not Paul Watson
|
|
|
|
|
|
Here is another one[^] which seems quite good. It talks about using an xsi:null instance to handle DBnull values.
Paul Watson Bluegrass Cape Town, South Africa Ray Cassick wrote: Well I am not female, not gay and I am not Paul Watson
|
|
|
|
|
I have a long running stored procedure that populates a OUTPUT variable with values for each stage of the procedure.
What I would like to do is to have my C# app get these values during the course of the proc, but I'm not sure how to do this.
The procedure has numerous lines like:
SELECT @MyOutputVal = some_other_proc_that_returns_a_value
SET NO COUNT ON is being used, so obviously no intermediate vals are going to be returned at the moment.
Any ideas on how I need to structure the VC# code to catch the output values, values?
Cheers,
Simon
"VB.NET ... the STD of choice", me, internal company memo
|
|
|
|
|
The value of your output parameters will only be returned to your app when the procedure has finished. If that's all you need, all you have to do is set the Parameter.Direction property to ParameterDirection.Output . If you want values from different stages, but don't need them until the end of the procedure, you can use multiple output parameters.
If you need feedback during the execution, you can use PRINT commands in your stored procedure, and sink the InfoMessage event of the connection. When you call PRINT 'Some message' in the procedure, you'll get an InfoMessage event, and the Message property of the SqlInfoMessageEventArgs will contain the string you printed.
|
|
|
|
|
Thanks for the info, Richard.
I've forwarded this to my colleague.
Cheers,
Simon
"VB.NET ... the STD of choice", me, internal company memo
|
|
|
|
|