|
Return the @@ROWCOUNT from the query as an output parameter
|
|
|
|
|
I new to C# and mssql. this is my code:
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlDataReader rdr = null;
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT count(*) FROM training WHERE userid='genbox'", conn);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Response.Write(#WANT COUNTER HERE#);
}
rdr.Close();
conn.Close();
I figured that something like SELECT count(*) FROM... could be used, but if @@ROWCOUNT is better, i will use that instead.
|
|
|
|
|
Oh, ok two ways - both exactly the same, but one is a tonne more readable.
You are returning the count as the first column in a select list so you can just go:
while (rdr.Read())<br />
{<br />
Response.Write(rdr[0].ToString());
}
However, you can make this much more readable by aliasing the column as a name
SqlCommand cmd = new SqlCommand("SELECT count(*) AS TrainingCount FROM training WHERE userid='genbox'", conn);
now:
while (rdr.Read())<br />
{<br />
Response.Write(rdr["TrainingCount"].ToString());
}
HTH!
-- modified at 7:22 Friday 16th December, 2005
|
|
|
|
|
Thanks, it sort of works. :S
Cant i use the same SqlCommand to extract data from the tabel ?
if i exec this:
while (rdr.Read())
{
Response.Write(rdr["TrainingCount"].ToString());
}
then it returns the number of rows like it should, but if i read any data from the table, then it returns an error. - this is the code:
while (rdr.Read())
{
Response.Write(rdr["TrainingCount"].ToString());
Response.Write(rdr[1]);
}
And this is the error:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
Do i really have to make 2 SqlCommands, one that counts and one that i can get data from? that dosent seem right to me.
|
|
|
|
|
Does anyone know of a tool (preferably free) to determine the location of boxing/unboxing within a project.
The aim is to improve performance and justify all boxing operations.
Thanks
LiamD
|
|
|
|
|
You could use ildasm.exe from the .NET Framework SDK to disassemble the assembly to IL and search for "box" and "unbox". But if you're aim is to determine how ths impacts performance you should use a code profiler. There are many already available for the .NET Framework - both free and commercial - and they aren't too terribly difficult to write if you'd rather do that.
The CLR Profiler for the .NET Framework 2.0[^] is one developed at Microsoft and is used in a lot of MSDN articles as wellas in blogs like Rico Mariani's[^], who's responsible for performance in the Developer Division. Not only will it help you determine where boxing is performed but also how often and how much impact is has on your application's performance.
Also remember that any time you treat a number, struct, or enumeration as a reference type (anything that derives from System.ValueType ) boxing will occur. This is one of many great reasons for generics (similar to C++ templates) in the .NET Framework, so that you can avoid boxing like so:
ArrayList list = new ArrayList();
list.Add(1);
list.Add(2);
list.Add(3);
List<int> list = new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
hi
I need free C# 2005 ebook.
Can give me link(s) to it, please?
Best wishes
|
|
|
|
|
|
Yup no better book than MSDN itself....
Bikash Rai
|
|
|
|
|
http://www.e-sertifika.net/ebookmicrosoft.htm
http://www.easyfilehost.com/?file=1131581215
http://www.liukun.com/puzzle/parvon/book
|
|
|
|
|
|
|
in extended columns i press tab and cursor jumjps 2 cells. How could i solve this problem?
|
|
|
|
|
Hi,
I am doing an asynchronous call as below.
Initially in the method EmployeeDetailsUpdate I had:
//ws.EmployeeDetailsUpdate(intEmployeeID, strTitle, dtBirthDate, strNotes);
as you can see below in the code.
Then I comment it out and replaced it with the async call.
The code runs fine. I just thought I get a professional look into this.
So do you think my asynchronous call is correct?
Please have a look at both the methods below.
Thanks
public void EmployeeDetailsUpdate(int intEmployeeID, string strTitle, DateTime dtBirthDate, string strNotes)
{
try
{
EmpService.Employees ws = new EmpService.Employees();
//ws.EmployeeDetailsUpdate(intEmployeeID, strTitle, dtBirthDate, strNotes);
//Asynchronous call...
AsyncCallback acb = new AsyncCallback(HandleCallbackUpdate);
ws.BeginEmployeeDetailsUpdate(intEmployeeID, strTitle, dtBirthDate, strNotes,
acb, ws);
}
catch
{
throw;
}
}
private void HandleCallbackUpdate(IAsyncResult ar)
{
try
{
EmpService.Employees ws;
ws = (EmpService.Employees)ar.AsyncState;
ws.EndEmployeeDetailsUpdate(ar);
}
catch
{
throw;
}
}
|
|
|
|
|
|
I just spotted an issue here.
This asynchronous call is on the business layer where it calls the webservice.
On the client side, when the webservice call has ended, it calls another method to populate a datagrid on the windows form.
So, since it is an async call now, before the end... is called, it sometimes calls the populatioin of the grid. So the grid gets populated before the end... call is called (Therefore incorrect population).
So should I still be using the async call here?
Hope you follow what I mean.
Thanks
|
|
|
|
|
Hi everybody, i'd like to know ('cause I'm on my first experience with c#) if it is possible with xmltextwriter, to write a new node in a specified position.
Thank you
|
|
|
|
|
Not with an XmlTextWriter , no. That is used to merely write out XML forward-only, appending elements, fragments, etc. all moving forward. If you want to open an existing XML document and add an element in a certain position use the XmlDocument to load the XML and use one of the XPath methods like SelectSingleNode to find the node you want, then either prepend or append the node you want to add like so:
class Program
{
static void Main(string[] args)
{
string xml = @"<?xml version=""1.0""?>
<root>
<child id=""one"">
<grandchild id=""a""/>
<grandchild id=""b""/>
</child>
<child id=""two"">
<grandchild id=""c""/>
<grandchild id=""d""/>
</child>
</root>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNode node = doc.DocumentElement.SelectSingleNode(@"child[@id=""two""]");
if (node != null)
{
XmlElement elem = doc.CreateElement("grandchild");
elem.Attributes.Append(doc.CreateAttribute("id"));
elem.Attributes[0].Value = "e";
node.AppendChild(elem);
}
using (XmlTextWriter writer = new XmlTextWriter(Console.Out))
{
writer.Formatting = Formatting.Indented;
doc.WriteTo(writer);
}
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thank you so much...in fact I was reading msdn documentation for xmlDataDocument...now I'll go trying...thanks agains
|
|
|
|
|
Be aware that the XmlDataDocument is really designed for a DataSet or similar schema. If you're XML fragment is more complex you should stick with XmlDocument .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
well, now...i have the following structure of my xml file:
- <engine_data>
<type id="Variables">
<type id="Parameters">
<type id="BreakPoint">
Now a I want to add dynamically new nodes under Variables, Parameters and BreakPoints, and for each subnode I have many properties to store, any suggestion?
|
|
|
|
|
<br />
<Engine_Data><br />
<Type id=""Variables""><br />
</Type><br />
<Type id=""Parameters""><br />
</Type><br />
<Type id=""BreakPoint""><br />
</Type><br />
</Engine_Data><br />
<br />
|
|
|
|
|
You need to change < to < and > to >, or check "Ignore HTML tags in this message" when posting SGML-derivative code like HTML and XML.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Afternoon!
Hello to everyone! My partner and I want to write in a voice conversation program, and we are making use of C#. And now, I can catch the voice from the sound card and store it in the buffer. But now I have a trouble in a big problem. “I can convey a voice file to another. But what should I do when my files pass that can make another client read-out the files and broadcast it.” (That the files are in the buffer.)
Now! In an emergency, mail to u9213120@yuntech.edu.tw
When I have received help from yours truly makes me more skillful.
Thank you for your attention!
|
|
|
|
|
Hi. I tried asking this question in ZedGraph article, but I got no answer.
I have a database with some data that I would like to be represented in graphs.
The database is like this:
exercise | weight | maxweight
squat | 100 | 120
deadlift | 120 | 130
rows | 50 | 20
<- edit: the spaces may not show correctly ->
I would like to represent the values from each exercise in graphs. but i have no idea how to do that. - i'm using the "bar-graph" from ZedGraph.
I would also like the graph to be dynamic, so that if a user inserts a new exercise, then the graph will extend with another graph.
this is what i have currently:
private void OnRenderGraph(System.Drawing.Graphics g, ZedGraph.MasterPane mPane)
{
GraphPane pane = mPane[0];
pane.Title = "Training";
pane.YAxis.Title = "Exercise";
pane.XAxis.Title = "Weight (kg)";
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlDataReader rdr = null;
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT exercise FROM training WHERE userid='"+ Page.Request.Params["userid"] +"'", conn);
rdr = cmd.ExecuteReader();
rdr.Read();
double[] x = { 50, 30, 50 };
BarItem myCurve = pane.AddBar("Weight", x, null, Color.DarkGreen);
myCurve.Bar.Fill = new Fill(Color.DarkGreen, Color.LightGreen, Color.DarkGreen, 90f);
string[] labels = { rdr["exercise"].ToString() };
pane.YAxis.TextLabels = labels;
rdr.Close();
conn.Close();
// Draw the Y tics between the labels instead of at the labels
pane.YAxis.IsTicsBetweenLabels = true;
// Set the YAxis to Text type
pane.YAxis.Type = AxisType.Text;
// Set the bar type to stack, which stacks the bars by automatically accumulating the values
pane.BarType = BarType.Stack;
// Make the bars horizontal by setting the BarBase to "Y"
pane.BarBase = BarBase.Y;
pane.AxisChange(g);
}
I am very new to C# and asp.net.
I know that i should put the rdr.Close() and conn.Close() into an exception with the rest of the sql connection, but i'm still testing.
|
|
|
|