|
Use Count in stead of sum
SELECT COUNT(*) FROM Table WHERE Condition
|
|
|
|
|
Eduard, thanks much for your answer. Can you please tell how do i get that value and print it.
for example given condition meets 200 rows. how do I get that 200 and display it on the screen.
thanks a lot.
|
|
|
|
|
Do you already have a connection to the database?
object oRowCount = Command.ExecuteScalar();
int iRowCount = (oRowCount == null) ? 0 : int.Parse(oRowCount.ToString());
|
|
|
|
|
I don't know what do you mean by condition but this is what I have Or I am doing.
(I am very new to database. I get done most of it but I have problems here and there).
con = new SQLiteConnection(@"Data Source= MyData.db;Version=3;New=False;Compress=True;");<br />
con.Open();<br />
cmd = new SQLiteCommand();<br />
cmd = con.CreateCommand();<br />
cmd.Connection = con;<br />
cmd.CommandText = "SELECT COUNT(Call)FROM Hall_Call_Up WHERE Car = 3";
I don't know if this is make sense to you or Not.
thanks again.
|
|
|
|
|
I did not say 'condition', I said Connection
After the cmd.CommandText paste this code :
object oRowCount = cmd.ExecuteScalar();
int iRowCount = (oRowCount == null) ? 0 : int.Parse(oRowCount.ToString());
|
|
|
|
|
jashimu wrote: COUNT(Call)
COUNT(Call) and COUNT(*) are two different things; are you sure you want COUNT(Call)?
|
|
|
|
|
Eduard, Thanks it work for me. that is all I needed.
thanks again for your help.
|
|
|
|
|
Eduard Keilholz wrote: int.Parse(oRowCount.ToString()
That is entirely inefficient -- I hope you don't write production software that way. The value is already an int; you just need to tell the compiler that it is by casting it. Never turn a value into a string and then parse it right back to the type that it was.
And, in this case (counting records), the value will never be null* (though it may be zero); so you needn't check for that.
int iRowCount = (int) Command.ExecuteScalar() ;
* Something is tickling the back of my brain saying that this is an untrue statement, but I can't remember in what circumstances I've run into trouble before. So I'll say it and maybe someone else will remind me.
|
|
|
|
|
I am not an expert in sql so I listen who ever says anything and works That is all I care fore, at least now. But I will try what you just said.
Eduard code worked for me but I don't know it is not a best option that only experts know.
thanks for your feedback.
|
|
|
|
|
I've got SQL 2005 Express and db located on server. Clients computers connect to it and server application also connect to db to perform SQL queries.
How to enable simultanious access to db?
If server connected to db, it remains unavailable for connections from client with error:
System.Data.SqlClient.SqlException in Void OnError(System.Data.SqlClient.SqlException, Boolean): Cannot open user default database. Login failed.
Login failed for user 'NT AUTHORITY\SYSTEM'
Or vice versa, if client connected to db and read some date, server can not connect to it for some period of time
Чесноков
|
|
|
|
|
This is not an error with simultaneous connections but rather with authentication.
There is no limit on the number of connections in SQL 2005 Express.
|
|
|
|
|
Make user accounts and associate with a login.
I think it supports multiple users if not the database is altered as Single User.
|
|
|
|
|
I'm not versed in SQL server management.
When I created database in VS it gave default connection string which I'm using:
Data Source=.\SQLEXPRESS;AttachDbFilename=C:\dbs\MyDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
I've got SQL 2005 express and managment tools.
How to add those users and change connection string param?
Currently, single applicaion engages db file resulting in:
System.Data.SqlClient.SqlException in Void OnError(System.Data.SqlClient.SqlException, Boolean): Cannot open user default database. Login failed.
Login failed for user 'NT AUTHORITY\SYSTEM'.
Until application is closed or some period of time elapses, MyDatabase.mdf becomes engaged as you neither can not delete it nor open.
How to manage that multiple clients connections to single db?
Чесноков
|
|
|
|
|
It is an authentication issue. Why is your app trying to connect as SYSTEM user ? Are you trying to connect from a windows service ? Whatever the case may be, if you are using Windows Authentication, ensure that the user is trusted with SQL Server or use SQL Server authentication.
|
|
|
|
|
|
hai....help me plz....urgent
i create data table for treeview lik dis
with hospital name as treenodes|Dr names as subnodes .. Apolo|Dr.jhon
Image|Dr.Krish
Care|Dr.Ram
Apolo|Dr.sri
Image|Dr.prabhu
Care|Dr.san
i want treeview display lik dis....
-.Apolo
. .
. .
. .Dr.jhon
. .Dr.sri
.
-Image
. .
. .
. .Dr.prabhu
. .Dr.Krish
.
-Care
.
.
.Dr.Ram
.Dr.san
but in treeview it displaying lik dis..it opening in another treenodes with single name..
-.Apolo
. .
. .
. .Dr.jhon
.
.
-Image
. .
. .
. .Dr.prabhu
.
.
-Care
.
.
.Dr.Ram
-.Apolo
. .
. .
.
. .Dr.sri
.
-Image
. .
. .
.
. .Dr.Krish
.
-Care
.
.
.Dr.san
thanqu....
|
|
|
|
|
Its because you have to add your Doctor nodes as children of your hospital ones.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
It is because you are adding everything to the TreeView's Nodes collection. You have to take care of the hierarchy, TreeView cannot automatically do it for you.
TreeNode hostpitalNode;
hostpitalNode = treeView1.Nodes.Add("Apolo");
hostpitalNode.Nodes.Add("Dr. Krish");
And while posting, follow the guidelines, it is 'urgent' for you, not for others.
|
|
|
|
|
hai...sory sory...im new for thees messages ......i dono how 2 write...forgive me yar...
any ways thanqu for ur reply....
|
|
|
|
|
hai...Shameel.....yah i tried ..but again it displaying in hierarchy manner...i dont want Dr's name displaying in another same hospital name....
(actuly i given in Data table ,,in same hospital name with 2 Dr's names....but...its displaying in 2 different treenodes...i want 2 show in single hospital name with 2 Dr's names)
Apolo|Dr.jhon
Image|Dr.Krish
Care |Dr.Ram
Apolo|Dr.sri
Image|Dr.prabhu
Care |Dr.san
public void TreeviewBind()
{
query= "Select * from Clinic_tbl";
da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds, "Clinic");
foreach (DataRow row in ds.Tables[0].Rows)
{
rootNode = treeView1.Nodes.Add(row[0].ToString());
rootNode.Nodes.Add(row[1].ToString());
}
}
i hope u understod my lang..im new for Dotnet...this is my 1st project.........thanqu
|
|
|
|
|
Your code does what you have asked it to do. It is your headache to find out if the hospital is already added to the TreeView and add your doctor there.
Hint: Use treeView1.Nodes.Find() to find out if the hospital is already added.
Your first problem is that your table is not normalized.
|
|
|
|
|
Marking the post as urgent and requesting urgent help is very rude around here.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
hai...sory sory...im new for thees messages ......i dono how 2 write...forgive me yar...
|
|
|
|
|
If you are new here then you should have read this[^] correct?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
hi sir,
i am work in c#. my problem user defined color change one form to another form
then help me,
pls reply me
|
|
|
|