|
The DataColumn object can be used to create an expression column:
productsTable.Columns.Add("SubTotal", Type.GetType("System.Single"), "Sum(Price)")
Hope this helps.
Andy
|
|
|
|
|
Hi, I run a sql file using ADO.Net and count the run time. But strangely, for the exactly same environment, same sql, but the run time are different. sometimes it has more than 30 seconds' differece. For example, first time it took 2 mins and 31 secondes, the next time it took only 1 minute and 54 seconds. Can anyone please tell me why and how to avoid this happens?
Thanks in advance.
|
|
|
|
|
What are you running the file against?
Queries in MS SQL Server can have different run durations as a result of SQL Server caching the data. (ie. keeping it in memory, rather than the timeconsuming task of reading it from disk,)
|
|
|
|
|
Thanks. I think that's the reason.
|
|
|
|
|
Also, if it's the exact same script, SQL Server will likely have cached the execution plan.
There's a compilation stage in each query where SQL Server decides which logical operators it will use to correspond to your query text. I was recently a little surprised to find that SQL Server often uses the Inner Join logical operation to implement the IN clause of a query. SQL Server terms this the execution plan.
If it can detect that you've used the same query, or one that only varies slightly (e.g. you've changed a value in a WHERE clause) it will reuse the cached execution plan. It might decide to try again if you've added some indexes or a whole load of new data which might change how useful the existing indexes are.
|
|
|
|
|
Hi
how can I get a list of tables from a database by using
the CADO Classes from Carlos Antollin?http://www.codeproject.com/database/caaadoclass1.asp)
Greetings
Thomas
|
|
|
|
|
Running this query will give you the names of all tables...
<br />
SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE'select * from information_schema.tables<br />
|
|
|
|
|
Firstly hi to all,
I want to learn is there anyone or anyplace that has all countries' icon flags in jpg or gif files.
I mean for example: for United States US.jpg for United Kingdom UK.jpg for Turkey TR.jpg.
I want like this since I've collected these countries in short forms to SQL and I want to call these images by /folder/(user.Country)"+".jpg"
Is there any better way to do this?
Any help will be appriciated
Arda
-
When in doubt, push a pawn!
-
|
|
|
|
|
I have a simple datagrid that i want to add a combo box to on e of the columns but can't find any information on how. Any help will be a start.
Chris
|
|
|
|
|
hi,
Firstly if you are using VS.NET right click the datagrid and select Edit Template and then click Item Template. Datagrid's apperance will change and then drag and drop the box(es) to the Item Template(the very first row). Finally right click the datagrid again and then select End Template Editing.
If you want further information and some simple dynamic codes for selecting a row here is the link that I know http://www.dotnetbips.com/displayarticle.aspx?id=147
Kind Regards,
-
When in doubt, push a pawn!
-
|
|
|
|
|
I do not see the "edit template" functionality. This is a datagrid in a window form, does that matter?
|
|
|
|
|
oh absolutely in windows applications it changes but I don't know about them.
Hope you can find a solution.
Kromozom
-
When in doubt, push a pawn!
-
|
|
|
|
|
I'm using asp.net, c#, and Sql Server. I'm calling a sp, and I'm getting an error back. I have the "ExecuteNonQuery" wrapped in a try/catch. I fall into my catch, but what is the best way to find out which column I'm getting a unique constraint error on?
I'm checking SqlException from my catch, and I notice that the SqlException.Number==2627. I also look in the SqlException.Message, and it has some good text in it.
The sp is inserting into a couple of tables, which each have a unique constraint on them.
Do I need to parse the SqlException.Message? Is there a cleaner way?
Thanks in advance,
|
|
|
|
|
when i search using ado's seek method on a multi- column index if the data entered matches partially the method returns true
example: an access table with an index consisting of first and lastname when i use the ADO seek method it finds a record even if i only eneter a firstname that exist and leave the last name blank
|
|
|
|
|
This is a wierd one!
I'm trying to use a transaction, when I try to execute the command I get the following error:-
The transaction assigned to this command must be the most nested pending local transaction
I've looked on the web and MSDN and can't find a reference to this error! Anyone got any ideas?
Dim myTrans As OleDbTransaction = conn.BeginTransaction(IsolationLevel.ReadCommitted)<br />
Command.Transaction = myTrans<br />
'Try<br />
myTrans.Begin()<br />
If UniqueID > 0 Then<br />
'it exists so update it<br />
Command.CommandText = "UPDATE PCLEquipment SET NoOff=NoOff+1 WHERE UniqueID=" & UniqueID<br />
Command.ExecuteNonQuery() 'FAILS HERE<br />
Else<br />
'it doesn't so add it<br />
Command.CommandText = "INSERT INTO PCLEquipment(PlayerID,EquipmentID,NoOff) VALUES(" & PlayerID & "," & ItemID & ",1)"<br />
Command.ExecuteNonQuery() 'FAILS HERE<br />
End If<br />
'subtract cost<br />
SpendMoney(Command, Money, PlayerID)<br />
myTrans.Commit()
|
|
|
|
|
Hi Lee
You have already started a transaction by calling the "conn.BeginTransaction " method - try removing the call to "myTrans.Begin " (which is used to created nested transactions).
Hope this helps.
Andy
|
|
|
|
|
Durr! <slaps himself="" on="" forehead="">
Thanks Andy
|
|
|
|
|
Hi,
our website is presently using Access as it's database. We are planning to redesign our website and we'd like to improve our database system. So I have a few questions:
1) What version should we use? 97, 2000 or 2002? Why?
2) Should we use Jet drivers or Access drivers (DRIVER={Microsoft Access Driver (*.mdb)}; )? I guess that questions 1 and 2 are related...
3) Is there a proper way to open and close a connection? For example, should I open a connection at the beginning of a page, let the recordsets found in the code use the same connection, and close that connection at the end of the page, when I'm done with it? Or should I use may different connections (like 1 connection for each recordset)?
Any other info/links are welcomed!
Thanks!
---------------
Tired of Spam? InboxShield 2.0.2 for Microsoft® Outlook® 2K/2K2/2K3
http://www.inboxshield.com
|
|
|
|
|
LukeV wrote:
What version should we use? 97, 2000 or 2002? Why?
Any version will do !
LukeV wrote:
Should we use Jet drivers or Access drivers (DRIVER={Microsoft Access Driver (*.mdb)}; )? I guess that questions 1 and 2 are related...
I've had the best results with the OLEDB (Jet) Driver
LukeV wrote:
Is there a proper way to open and close a connection? For example, should I open a connection at the beginning of a page, let the recordsets found in the code use the same connection, and close that connection at the end of the page, when I'm done with it? Or should I use may different connections (like 1 connection for each recordset)?
Use the same ADODB Connection, and just close it at the end of code execution
HTH
Tony
|
|
|
|
|
LukeV wrote:
What version should we use? 97, 2000 or 2002? Why?
2000 is good .. 97 is good too !!!
LukeV wrote:
Should we use Jet drivers or Access drivers (DRIVER={Microsoft Access Driver (*.mdb)}; )? I guess that questions 1 and 2 are related...
never use that one I had troubles with it
use jet 4.0
|
|
|
|
|
Have you considered migrating ot MSDE? Essentially the server engine from SQLServer 2K - should have it available on either the Office CD, or Visual Studio stuff - if you have that available, then even get the wazzy front end tools....think it's called the MSDE For Visual Studio o something similar
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
I have an issue with the use of parameters when attempting to talk to the database.
// This piece of code returns exactly what I expect
OleDbConnection myConnection = new OleDbConnection(ConnectString);
myConnection.Open();
OleDbCommand myCommand = myConnection.CreateCommand();
myCommand.CommandText = "SELECT statement FROM sys_sql " +
"WHERE key = 'clsDBNotesSelect'";
string strResult = (string) myCommand.ExecuteScalar();
myConnection.Close();
// This piece of code results in "An unhandled exception of
// type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"
OleDbConnection myConnection = new OleDbConnection(ConnectString);
myConnection.Open();
OleDbCommand myCommand = myConnection.CreateCommand();
myCommand.CommandText = "SELECT statement FROM sys_sql " +
"WHERE key = @KEY";
myCommand.Parameters.Add("@KEY", OleDbType.VarChar, 50);
myCommand.Parameters["@KEY"].Value = "clsDBNotesSelect";
string strResult = (string) myCommand.ExecuteScalar();
myConnection.Close();
I've tried several variations and methods. None will get me past the error. Any input is appreciated.
Dan
|
|
|
|
|
Hi Dan
The "@Key" syntax for parameters is required by the SQL-Server provider. For the OLEDB provider (that you seem to be using), you need to use question marks in the query text:
OleDbConnection myConnection = new OleDbConnection(ConnectString);<br />
myConnection.Open();<br />
OleDbCommand myCommand = myConnection.CreateCommand();<br />
myCommand.CommandText = "SELECT statement FROM sys_sql " +<br />
"WHERE key = ?";<br />
myCommand.Parameters.Add("@KEY", OleDbType.VarChar, 50);<br />
myCommand.Parameters["@KEY"].Value = "clsDBNotesSelect";<br />
string strResult = (string) myCommand.ExecuteScalar();<br />
myConnection.Close();
Note that I have not tested the above code.
Hope this helps.
Andy Harman
|
|
|
|
|
Thank you very much. All the references I have always talk about the Sql provider and I've had to stumble through several different oddities due to the OleDb provider.
Your solution does work but I've lost the uniqueness of the parameters. I tried to replace the @ with the ? (leaving KEY) but it didn't like that. What is the methodology used if the CommandText changes (which it will!) to something like:
"SELECT statement FROM sys_sql WHERE key = ? AND owner = ?"
Is it going to be based on the order of the parameters added? Therefore, the first one added belongs to "key = ?" and the second to "owner = ?"?
Thanks
Dan
|
|
|
|
|
OleDb does not support named parameters.
Yes you have to add them in order.
The first param will be the first ?
and so on.
Bo Hunter
<marquee behavior="alternate">Bo Hunter
|
|
|
|