|
here is my code:
public partial class Form1 : Form
{
string cs = @"Data Source=NADEEM-PC\SQLEXPRESS;Initial Catalog=School Managment System;Integrated Security=True";
static SqlConnection con = null;
static SqlCommand cmd = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
void Summary()
{
int Male_students;
int Female_students;
int Male_teachers;
int Female_teachers;
con = new SqlConnection(cs);
con.Open();
try
{
cmd = new SqlCommand("SELECT COUNT(*) FROM [Students Records] WHERE Gender='Male' ", con);
Male_students = int.Parse(cmd.ExecuteScalar().ToString());
cmd = new SqlCommand("SELECT COUNT(*) FROM [Students Records] WHERE Gender='Female' ", con);
Female_students = int.Parse(cmd.ExecuteScalar().ToString());
cmd = new SqlCommand("SELECT COUNT(*) FROM [Teachers Records] WHERE Gender='Male' ", con);
Male_teachers = int.Parse(cmd.ExecuteScalar().ToString());
cmd = new SqlCommand("SELECT COUNT(*) FROM [Teachers Records] WHERE Gender='Female' ", con);
Female_teachers = int.Parse(cmd.ExecuteScalar().ToString());
this.SM.Text = "" + Male_teachers.ToString() + "";
this.SF.Text = "" + Female_teachers.ToString() + "";
this.ST.Text = "" + (Male_teachers + Female_teachers).ToString() + "";
this.TM.Text = "" + Male_students.ToString() + "";
this.TF.Text = "" + Female_students.ToString() + "";
this.TT.Text = "" + (Male_students + Female_students).ToString() + "";
con.Close();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
}
i don't get the desire result on labels named SM,SF,ST,TM,TF,TT
please help me.. .
|
|
|
|
|
Well, you don't tell us what results you expect, or actually get, so we can't really say "do this and all will be well" but frankly there is a lot of redundancy in that code.
For example:
Male_students = int.Parse(cmd.ExecuteScalar().ToString());
Male_students is an integer.
ExecuteScalar returns an integer.
So why are you converting an integer to a string, in order to parse it and convert it back to an integer again?
And:
this.SM.Text = "" + Male_teachers.ToString() + "";
You don't need this at all, and what do you think adding a empty string at the start and end of a string is actually going to do? Anything?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I want to show the total number of male students in label names Sm and i don't get it!!
|
|
|
|
|
Yeah, I kinda guessed that...
Don't you think what you do get, and the number you know are in the DB might be relevant? Just a little?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
can't understand what r u saying??
|
|
|
|
|
Well, you run your code, yes?
It does something, yes?
What exactly it does do only you can see. (Remember that we can't see your screen, access your HDD, or read your mind, so we only get to work with what you tell us.)
So without knowing what it should do: "There are 15 male students, 12 female" and what it actually does do: "It shows 6 Male and 140 Female students" we don't have much to go on in the way of information.
We can't run your code and get the same results you do, because we don't have access to your database. So you need to tell us the information we can't find out any other way.
If you rang the garage and said "my car broke" you would expect them to want information like "what broke?", "where is it?", "was it the engine?", "have you run out of fuel?", and so forth, so why would you expect us to be any different?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
It doesn't show any number there is nothind no text on the label
|
|
|
|
|
No text at all? Ok.
You also said: "I want to show the total number of male students in label names Sm and i don't get it!!"
Which is possibly wrong because your code puts Male Teachers in there:
this.SM.Text = "" + Male_teachers.ToString() + "";
That means the code above isn't executed at all - because int.ToString cannot return an empty string - it will always return a number as a string, even if that number is zero.
So, if that code isn't being executed, and since you don't say that you get a MessageBox or a fatal exception, the most likely is that you aren't calling the Summary method at all. And a quick look at your code says you aren't calling it anywhere in the code fragment you showed us. If you don't call it, you don;t get any displayed values.
Did you mean to call it from your Form1_Load event handler perhaps?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
thank u sooooooo much u helped me alot
|
|
|
|
|
You're welcome!
(Just remember in future - the better the info you give us, the quicker we can give you a solution! )
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Tell your teacher that although it is allowed to have spaces in a table-name, and although it is supported, and even with it being merely an example and an excercise -
IT IS NOT DONE.
..and then I'd expect not to see the term "records" appended to that name. What else is going to be in there, icecream and zombies?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I was using IMultiValueConverter in my project in which I will be doing some business calculations. for this I will be using the following.
1. An DataTable
2. An XML and,
3. Some coloring logic.
I am trying to apply color for some cells in the DataGrid by performing an business calculation using the above mentioned together or any one of it. In all the cases am getting some lagging (slowness) in applying color to the deserved cell. but if I simply return color without performing an business calculation it works fine (So am sure that there is no mistake in applying or the way I integrated IMultiValueConverter) which means I was not calculating any business logics using the above mentioned things.
My Question was is there is any limitation in using IMultiValueConverter and IValueConverter in such a way that it was not overloaded with response time to the control to which it was bounded?
Note: please let me know if any one can't understand my question
_AKA_KSN_
|
|
|
|
|
_AKA_KSN_ wrote: In all the cases am getting some lagging (slowness) in applying color to the deserved cell. but if I simply return color without performing an business calculation it works fine (So am sure that there is no mistake in applying or the way I integrated IMultiValueConverter) It also proves that it's calculating the business logic that causes the slowdown.
_AKA_KSN_ wrote: My Question was is there is any limitation in using No, it's the business logic.
The UI-thread is responsible for drawing the UI, and it's a bad idea to put some BL in a presentation-layer.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
But we found a different cause for this problem, in my DataGrid we have enabled Virtualization and some common theme. when we disable those it works fine.
which mean the Ui takes long time to load the data and renders all the values in the UI. after that we don't need Convertors any more. so we planned to fix the bug in theme and have to do some enough study in enabling virtualization.
_AKA_KSN_
|
|
|
|
|
_AKA_KSN_ wrote: But we found a different cause for this problem, in my DataGrid we have enabled Virtualization Virtual Mode does not slow down the grid; on the contrary, it's used when databinding is too slow.
_AKA_KSN_ wrote: which mean the Ui takes long time The UI-thread is there to paint a UI, not to load data or do conversions.
_AKA_KSN_ wrote: have to do some enough study in enabling virtualization. There's a walkthrough here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It sounds to me like you are solving the wrong problem here. Rather than attempting to do business calculations in converters, you should create a ViewModel and perform your calculations in there. One of the overheads you have in a converter is that all elements are treated as objects, so you have unboxing to cope with.
|
|
|
|
|
hi, I use below code to create/consume and dispose sql connections.But as there are more than twenty methods/functions that I use it, same code block repeats. So, is it goog practice? Your valuable comments are welcomed.
private void islemKayitlariniYukle(string select)
{
using (SqlCeConnection sqlCEBaglantisi = new SqlCeConnection(Properties.Settings.Default.sqlBag))
using (SqlCeDataAdapter sqlAdaptor = new SqlCeDataAdapter(select, sqlCEBaglantisi))
using (DataTable dtTablo = new DataTable())
{
sqlCEBaglantisi.Open();
sqlAdaptor.Fill(dtTablo);
SqlCeCommand islemTipleriniAl = new SqlCeCommand("Select IslemTipi From IslemKaydi Group By IslemTipi", sqlCEBaglantisi);
using (SqlCeDataReader oku1 = islemTipleriniAl.ExecuteReader())
{
while (oku1.Read())
{ cmbIGIslemTipiSec.Items.Add(oku1.GetString(0).Trim()); }
}
|
|
|
|
|
teknolog123 wrote: same code block repeats. You could wrap some things in their own method
teknolog123 wrote: So, is it goog practice? Not if you're religious about the DRY-principle. In that case, there'd be a factory to return an IDbConnection , and the query-string would be passed to a method containing the database-connection logic.
Still, with or without the repeating code; I could work with it. If you'd use English names for your variables, I might even be able to understand it's intention
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
thanks let me explain more. I just want to dispose sqceConnection, sqlceCommand, SqlCeCommandBuilder and sqlceAdapter as soon as I finish processing the data. for example does the below code dispose the objects in that manner? I think no but wanna make sure. (note: I didn't use sqladapter and commnadbuilder below to keep the code short on purpose)
public SqlCeConnection sqlSetCon()
{
SqlCeConnection sqlCon = new SqlCeConnection();
sqlCon.ConnectionString = Properties.Settings.Default.sqlConnStr;
sqlCon.Open();
return sqlCon;
}
public DataTable returnDataTable(string selectString)
{
SqlCeDataAdapter sqlAdaptor = new SqlCeDataAdapter(selectString, sqlSetCon());
SqlCeCommandBuilder sqlKomut = new SqlCeCommandBuilder(sqlAdaptor);
DataTable dtTablo = new DataTable();
sqlAdaptor.Fill(dtTablo);
return dtTablo;
}
private void processList()
{
using (DataTable dt = returnDataTable("Select * From Customers Order By Surname"))
{
for (int i = 0; i < dt.Rows.Count; i++)
{
this.lblSurname.Text = dt.Rows[i]["surname"].ToString();
}
}
}
modified 2-Feb-14 6:38am.
|
|
|
|
|
Something similar to below; wrap the disposable's in a using-section, and they'll be disposed when they go out of scope.
public DataTable returnDataTable(string selectString)
{
using (var con = sqlSetCon())
using (SqlCeDataAdapter sqlAdaptor = new SqlCeDataAdapter(selectString, con))
{
DataTable dtTablo = new DataTable();
sqlAdaptor.Fill(dtTablo);
return dtTablo;
}
}
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
thanks Eddy, by the way, is it only those that are written in parentheses disposed or anything in curly braces?
|
|
|
|
|
teknolog123 wrote:
thanks Eddy, by the way, is it only those that
are written in parentheses disposed or anything in curly braces?
Anything that's disposable would be best in a using -clause. You can try it by putting it in a using, if it's not disposable you'll get a compiler-error saying so. Alternatively, you can check MSDN.
If you can't limit it to a scope, then you'd best dispose it from code later.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
how to use Switch Startup Project extension in visual studio 2012
|
|
|
|
|
You mean other than download it[^], install it, and follow the instructions on the page you got it from?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Actually ive downloaded from that site only , but i.e for VS2010,
do u have any idea that is there any extension for VS2012
|
|
|
|
|