darkagn 315 Veteran Poster Featured Poster

ExecuteScalar always returns a single value, so you should use it on any query that is expected to return a single record, single field result set. It's represented as object because its unknown what the correct data type should be but should be converted to whatever data type you expect. You will need to handle DBNull.Value during your conversion when using ExecuteScalar, but in your specific example this probably won't be necessary as your query should always either return an Int32 or throw an SQL exception if a timeout or connection error occurs for example.

Your other option would be to use ExecuteReader. This can be used to return the list of records with one or more fields, and then you iterate over the DataReader's Read() call to read each field from an array by column name or index. But in your example query this would be overkill and I would just use ExecuteScalar instead.

darkagn 315 Veteran Poster Featured Poster

I haven't used telerik specifically before but I wanted to mention that there is absolutely nothing wrong with using a third party to solve outstanding problems with a project. Sometimes it is just more cost-effective (not just in dollar value) to purchase another company's tools rather than trying to solve something yourself. You will need to do your homework on each tool that you use though, but often companies will offer a trial period for their products.

overwraith commented: Thanks for the thoughts. I usually do try to make life easier with third party, but sometimes the stuff is of questionable quality. +3
darkagn 315 Veteran Poster Featured Poster

Certainly being able to parse file input into something meaningful is always useful. To make it even more generic, why not use a Stream input instead? That way you can handle any input type (including files, via FileStream) so long as the format is what you expect.

overwraith commented: Good thoughts! +3
darkagn 315 Veteran Poster Featured Poster

Either set them to public or pass them in via the constructor. A third option is to have get public but set private. The syntax for this option is as follows:

public char suit { get; private set; }
public char value { get; private set; }

public Card(char aSuit, char aValue)
{
    suit = aSuit;
    value = aValue;
}

This option means that the card's suit and value can be accessed in a read-only manner from outside the instance.

darkagn 315 Veteran Poster Featured Poster

Use the SelectionStart and SelectionLength properties to select a particular part of the text and then apply formatting to it.

Example:

richtextbox1.SelectionStart = 30;
richtextbox1.SelectionLength = 10;
richtextbox1.SelectionAlignment = HorizontalAlignment.Left;

will align the substring starting at index 30 of length 10 to the left. I'm not sure how multiple alignments on the same line will work though but I'll leave that for you to test.

darkagn 315 Veteran Poster Featured Poster

Not sure if you can actually track that mouse event but you could handle the FormClosing event instead.

darkagn 315 Veteran Poster Featured Poster

You will have a file called Program.cs. This is the execution entry point of your application - or more specifically, the static method called Main in this file is. In this method, one of the last lines of the Main method reads something like:

Application.Run(Form1);

Change Form1 (or whatever form it actually reads in your file) to be the type of form you want displayed as the first view of your application.

darkagn 315 Veteran Poster Featured Poster

I would suppress the field so that the numbers are hidden from view, then put a plain text field with asterisks over the top of it.

darkagn 315 Veteran Poster Featured Poster

You can suppress the value in Crystal so that it doesn't show up, but then include it in the totals. That's probably easier than trying to mess with your SQL so that you can get the desired data pulled into the report.

darkagn 315 Veteran Poster Featured Poster

I haven't used MonoDevelop, but looking at their website they support a cross-platform interpretation of C# 3 (which is old given 4.5 was released in 2012 for Windows 8 and Server 2012, and 3 was released in 2006 with Vista and Server 2008). Debugging complex code would be interesting using such a middle manager too.

I believe a better approach would be to run VMWare with a Windows OS. This will give you a much closer experience to C# development than any attempt at trying to make .NET "cross platform" which is not its intended purpose.

darkagn 315 Veteran Poster Featured Poster

I'm not sure that you can develop C# applications on an IOS operating system. The .NET Framework is a Microsoft technology, so C# is not cross-platform like Java or PHP. If you only have access to a Mac, my suggestion would be to install a virtual machine running a Windows OS and use Visual Studio as your IDE (there are Express editions available for free for non-commercial purposes).

darkagn 315 Veteran Poster Featured Poster

To stop it from happening in the future, consider adding a primary key to the table. By definition a PK is not nullable and will help identify the records when they are inserted. For more information on primary keys see this W3Schools page on the subject.

darkagn 315 Veteran Poster Featured Poster

If you look at your declaration of _list, it is a List of type list2 objects. This means that all objects added to the list must be of type list2 or inherit from type list2. The list1 type inherits from the List<int> type, so it can't be added to the list since it is not a list2 type and it does not inherit from a list2 type.

darkagn 315 Veteran Poster Featured Poster

You can use the lock keyword for this. The basic idea is that you lock a private constant object whenever you read or write from the shared variable. Like this:

public class MyMultiThread
{
  private const Object lockObject = new Object();
  private int sharedVariable;

  public MyMultiThread()
  {
    WriteSharedVariable(0);
  }

  public void WriteSharedVariable(int aValue)
  {
    lock(lockObject)
    {
      sharedVariable = aValue;
    }
  }

  public int ReadSharedVariable()
  {
    lock(lockObject)
    {
      return sharedVariable;
    }
  }
}
darkagn 315 Veteran Poster Featured Poster

Have you tested the Convert.ToDouble function against the Double.TryParse function? I'm not sure if it's faster, but it is generally the preferred approach as it handles exceptions for you.

EDIT: There is also a TryParse static function for each of the other "primitive" types (Int32, Decimal, Byte etc).

darkagn 315 Veteran Poster Featured Poster

Something like the following query should get you close:

-- need a count of the objects by description and transaction
SELECT Description.Name, COUNT(Item.Name) AS count, COUNT(Transaction.Type) AS [under repair]
FROM Description
-- describe the relationship between the tables by joining
INNER JOIN Item ON Description.DeID = Item.DeID
INNER JOIN Transaction ON Item.IID = Transaction.IID
-- only interested in repair transaction type
WHERE Transaction.Type = 'Repair'
-- because we use aggregate functions, need to describe how to group the aggregations (counts)
GROUP BY Description.Name

Have a play with that query, it may need to be adjusted to get the right results but should give you a start.

darkagn 315 Veteran Poster Featured Poster

Your method example creates a new instance of the myClass class EACH TIME it is called, and stores the value of the parameters in its own instance variables. This is thread-safe.

I'm not sure that ALL static methods are thread-safe though. It is possible to access static global variables that are potentially shared by multiple threads from within a static method.

I'm sure there are probably other ways in which a static method could be thread-unsafe but it's late here in Australia and I can't think of another example right now sorry!

Someone please correct me if I'm wrong!

darkagn 315 Veteran Poster Featured Poster
darkagn 315 Veteran Poster Featured Poster

Thread.Abort() or Thread.Join() are the two simplest ways of ceasing a thread from running. What issue do you have with Thread.Abort()?

darkagn 315 Veteran Poster Featured Poster

If InsuranceDetails can be null, you need to use a LEFT JOIN to join your tables together.

SELECT 
  ipd.InPatientID,
  ipd.Fname+' ' +ipd.LName as 'Patient Name' , -- this line is dangerous if name(s) can be null
  ipd.Gender,
  ipd.BirthDate,
  ipd.AccType as 'Account Type',
  ipd.Minor,
  ipg.GFName+' ' +ipg.GLName as 'Guardian name', -- same here
  ipd.Insured,
  ipi.Insurance1,
  ipi.Policy1,
  ipi.GroupNo1,
  ipi.Guarantor,
  ipi.Employer
from
  HMS.dbo.PatientDetails ipd
inner join -- inner join means all conditions in "on" must be true
  HMS.dbo.ParentDetails ipg
on
  ipd.InPatientID = ipg.InPatientID
left join -- left join means the "on" can be true or null for ipi (right of the join)
  HMS.dbo.InsuranceDetails ipi
on
  ipd.InPatientID = ipi.InPatientID
poojavb commented: thank you very much....worked well +4
darkagn 315 Veteran Poster Featured Poster

Not sure if this is your only problem, but I noticed this line straight away:

int zoom=50/100;

So zoom = 0 which means that newWidth and newHeight both equal 0 too, so you are trying to create a Rectangle 0x0 and draw the image in that space. You see what I'm getting at?

double zoom = 0.5;
// or double zoom = 50.0/100.0;

is a better way to do it, but I would suggest allowing this value to be input by the user?

darkagn 315 Veteran Poster Featured Poster

If you want to mutate the string parameter you must declare it var in the procedure's signature:

procedure TMainForm.Show(var s: String);

But a better method would probably be to declare a local variable string to handle your error line, so:

procedure TMainForm.Show(s: string);
var
  n, n2, n3: integer;
  arTemp: TMyArray;
  tempStr: String;
begin
  arTemp := TMyArray.Create();
  n := InStr(1, s, ':');
  if n = 0 then

  tempStr := mid(s, n + 1);
  arTemp.SplitIn(tempStr, ':');
  //...
end;
darkagn 315 Veteran Poster Featured Poster

Transactions are very important in SQL. They provide a way of reverting previous steps of a multi-step operation on the database that causes changes should an error occur.

Imagine this simple, common scenario. You want to represent a sale of items as a header (containing the date and time of the sale, customer details and miscellaneous information regarding the sale as a whole) and several detail lines each representing the quantity and total cost of each item in the sale. If you have 100 different items in your sale, then the total number of records to be inserted in the database is 101 - 1 header record and 100 detail records in two separate tables. What happens if item number 76 has some error when inserting, maybe the price of the item hasn't been set yet? Without a transaction in place, you would have inserted the header and 75 correct detail records, leaving you with erroneous data in your database. Using a transaction we can "ROLLBACK" the transaction, leaving the database the way it was before we began inserting our records for the sale.

I hope this helps you understand where transactions are useful.

M.Waqas Aslam commented: awesome way to explain , simple and effective example. +5
darkagn 315 Veteran Poster Featured Poster

Here is a sample of how to insert/update image data. The sample code uses SqlClient instead of OleDB, but it should be a similar process.

Your algorithm should be:

1. Read image file into MemoryStream using the Image.Save function.
2. Convert the MemoryStream to a byte[] using Stream.ToArray function.
3. Add parameter to the SQL command, set value to the byte[] and DbType to DbType.Image.
4. Execute the SQL via the ExecuteNonQuery function.

Hope this helps :)

EDIT: Also, you aren't setting the parameters correctly in the SQL. Your query should look like this:

string comm = "INSERT INTO pictable (picId, picDirectory, pic, caption) values(@picId, @picDirectory, @pic, @caption)";
darkagn 315 Veteran Poster Featured Poster

You need the reference to prjform to be global in the class calling the mouse click method.

Example:

Project1.Form1 prjform = null;

private void mouseClkbtn_Click(object sender, EventArgs e)
{
  if (btnLatch.Text == "Latch Enable") // might be safer to use if (prjform == null) instead
  {
    prjform = new Project1.Form1();
    prjform.Show();
    btnLatch.Text = "Latch Disable";
  }
  else
  {
    prjform.Close(); // close calls hide and dispose
    prjform = null; // dereference here
    btnLatch.Text = "Latch Enable";
  }
}
darkagn 315 Veteran Poster Featured Poster

The SetResolution function accepts to float's as parameters, you are passing to int's. To fix your error you need to pass like so:

back.SetResolution(300.0F, 300.0F);
darkagn 315 Veteran Poster Featured Poster

Ah sorry I misread your OP and missed the part about IGNORE_DUPLICATE_KEY. Note that this option cannot be set to ON for a non-unique index, so it really only applies to unique indexes. When this option is ON, only a warning will be generated but the insert or update containing a duplicate will be allowed. When OFF (which is the default), the error is raised and the transaction is rolled back as I described earlier.

For an index on columns A, B and C that is unique, rows are considered duplicates if row1.A = row2.A AND row1.B = row2.B AND row1.C = row2.C. Note that this doesn't mean that column A = column B = column C, just that the values in the two rows match.

darkagn 315 Veteran Poster Featured Poster

A non-unique index allows duplicates to be inserted where a duplicate is defined as having the exact same values across each of the columns in the index. A unique index will raise an error and rollback an insert or update transaction when this check is failed.

If the CREATE INDEX query does not include the CLUSTERED or NONCLUSTERED key words, then the index will be a NONCLUSTERED index by default.

darkagn 315 Veteran Poster Featured Poster

So you want the equivalent of sbyte myInt8 = 9; but with a struct? It sounds to me like you want to overload the = operator which is not possible in C# (although you can overload other operators such as +, - and == ). As far as I know, it isn't possible to create a value type in C#, they are all native to the language.

A struct holds a series of values in its properties, so you access them in the same way as a class, not as a value type, even though the struct itself is stored on the stack.

A good example of a commonly used struct is the DateTime struct which can be found in the System namespace. If you look at the way the DateTime is used, you can do the following:

DateTime myDT = new DateTime();
myDT.Year = 2011;
myDT.Month = 12;
myDT.Day = 30;
myDT.Hour = 10;
myDT.Minute = 9;
myDT.Second = 31;
myDT.Millisecond = 912;
if (myDT.Day == 31 && myDT.Month == 12)
  Console.WriteLine("It's New Year's Eve today! Happy New Year!");

Note that you can't write myDT = "2011/12/30 10:09:31.912"; or something similar, because the compiler doesn't know where to store that string. However, you can do myDT = DateTime.Now.AddDays(1); because the AddDays function returns a DateTime type.

I hope this helps, but please let me know if I can explain further.

darkagn 315 Veteran Poster Featured Poster

Check out these two links:

Structs Tutorial
Objects, Classes and Structs

Think of a struct as a record of data. Basically a struct is similar to a class in that it groups together a bunch of data and methods that can be used by an instance. The two main differences are:

1. An instance of a struct is a value type while an instance of a class is a reference type. A struct is created on the stack while a class is created on the heap.
2. Classes can inherit from a base class while structs cannot.

I hope this helps your understanding, please re-post if you want more information.

darkagn 315 Veteran Poster Featured Poster

Check out the IComparable and IComparable<T> interfaces which can be used in conjunction with IComparer and IComparer<T> interfaces to implement a sorting class.

Example.

darkagn 315 Veteran Poster Featured Poster

You can use a try-except block like so:

try
  begin
    Example(6);
    Example(8);
    Example(10);
    Example(15);
    Example(7);
    Example(1);
  end
except on E: Exception do
  raise Exception.Create(E.Message); // raised as a new exception so will include the line calling Example(15) as the error line
end;
darkagn 315 Veteran Poster Featured Poster

Each Control has a Parent attribute, so you could use something like the following Linq statement to get just the "top-most" controls.

var controls = this.Controls.Where(o => o.Parent.Equals(this));
darkagn 315 Veteran Poster Featured Poster

Here is a solution for you (on another forum), it appears that this error code has to do with windows permissions.

darkagn 315 Veteran Poster Featured Poster

I do have one program that I wrote for a past assignment with two-dimensional arrays. I have already turned it in and am willing to take whatever I get on it but I would like to have an explanation of what I've done wrong or what I am missing. I hope I'm not imposing when I ask if this is something you would be willing to take a look at as well?

Absolutely, please feel free to ask questions about whatever you need. That's what DaniWeb is all about! I have always said that the best way to learn is to make mistakes and find out what went wrong.

However it might be a good idea to start a new thread for your new topic.

darkagn 315 Veteran Poster Featured Poster

So far I've been doing fairly well but i seemed to do better in C++...*sigh*.

I feel completely the opposite, C++ confounds me!

I'm pretty sure the random number generator in C# uses the current system time in milliseconds to generate its next int. This means numbers generated in the same millisecond by the same instance of Random will be the same. One solution might be to Thread.Sleep(1); between each generation to ensure you get a tick between them.

Good luck and have fun!

darkagn 315 Veteran Poster Featured Poster

The first thing I notice looking at your code is that the "and-ed" if-statement should be before your "or-ed" if-statement, because and's will always be false if or's are. I'm not 100% sure, but I think the statements int index3 = new int(); should be replaced by simply int index3 = rand.Next(imageListFruit.Images.Count); like you have for index1. Also, are you sure you need to basically duplicate the code from the GamePlay method in the btnExit_Click method?

darkagn 315 Veteran Poster Featured Poster

There is an error in your SQL query. I would suggest printing out your query string variable to see what is actually being inserted into your where clause with the values you are adding on the fly.

As an aside, a much safer approach to SQL is to use a parameterised query. Here is an example:

using (SqlConnection conn = new SqlConnection(connString))
{
  conn.Open();
  try
  {
    using (SqlCommand cmd = conn.CreateCommand())
    {
      cmd.CommandText = "SELECT * FROM Aircraft WHERE AircraftType = @Type";
      SqlParameter param = cmd.CreateParameter();
      param.ParameterName = "@Type";
      param.Value = aircraftType; // some value
      param.DataType = DbType.String; // some type
      using (SqlReader rdr = cmd.ExecuteReader())
      {
        while (rdr.Read())
        {
            // do something with the data
        }
      }
    }
  }
  catch (Exception e)
  {
     // do some error handling here
  }
  finally
  {
     conn.Close();
  }
}
darkagn 315 Veteran Poster Featured Poster

There are plenty of datetime functions in PHP that may be useful to you. Here is a list of many of them, date_add and date_parse could both be useful to you depending on how you want to do it.

darkagn 315 Veteran Poster Featured Poster

Its much easier to use decimals, however you can use "fractions" by simple addition and division. For your example, 1 1/2 = 1+(1/2) although this can also be written 1+1/2 since division takes precedence.

darkagn 315 Veteran Poster Featured Poster

For part A, they are wanting a function that uses the specific fields in your table, not passes them as parameters to the function. Your function will probably look something like this:

-- give the function a meaningful name, and return an appropriate data type
CREATE FUNCTION GetItemTotalPrice() RETURN MONEY
AS
DECLARE @TotalPrice MONEY
-- total price is defined as quantity x unitprice from the sales table
SELECT @TotalPrice = Quantity * UnitPrice FROM Sales
RETURN @TotalPrice

For B you will need to do a CREATE TABLE statement. Here is a link to the MSDN documentation for such a statement, there are also many many examples online. Have a try and repost if you need more help, along with your attempt.

darkagn 315 Veteran Poster Featured Poster
for (int i = 0; i < textBox3.Text.Length;i++ )
{
 
c = i+1 ;
 
 
if (textBox3.Text.Substring(i,c)==" ")
{
string word = null;
word = textBox3.Text.Substring(0, i);
arrayKeyword[index]=word;
index = index + 1;
}
}

Your for-loop here iterates from the start of the string textBox3.Text to the end of the string. During each iteration, you check the current character (at position i) and the one following it (at position c). So when i is the last character in the string, c is invalid because there is no character following position i. You need to change your loop like so:

for (i = 0; i < textBox3.Text.Length - 1; i++)

EDIT: Actually, substring takes a start position and a length of the string, so your call to substring should be:

if (textBox3.Text.Substring(i,1)==" ")
ddanbe commented: well explained. +14
darkagn 315 Veteran Poster Featured Poster

This is a static call to your function, which is fine if there is no calls to member variables or functions in the getAllRecords function (ie using $this). From a relatively early version of PHP (around PHP4 from memory) they introduced the static keyword which was supposed to be used to mark such functions as being able to be called in the manner you describe, but it was only intended as a guide and not enforced at runtime.

In general, non-static calls to functions go like this:

$myRecords = new getRecords();
$myRecords->getAllRecords();

That is, you instantiate an object of your class and then call the function that you need.

Hope this helps,
darkagn

darkagn 315 Veteran Poster Featured Poster

The line:

echo "</tr><td style='border-style:none; border-width:medium;'>";

is at fault I think. You close the row with the </tr> followed immediately with a <td> node. Are you able to view the source in the browser? I think you will find that you will have cells (<td>) outside of rows (<tr>) because of the line mentioned above, which will confuse the browser when it renders the table.

Also, you have some <p> tags that aren't closed, and your <img> tags aren't closed either.

darkagn 315 Veteran Poster Featured Poster

Resources are global, external data objects that can be used by the application from any point. Here is the MSDN description of application resources, their purpose and how to use them.

In answer to your third question, you can change what type of resources you wish to view/add/delete by changing the combo box that reads Strings when you open the resx file for the first time.

darkagn 315 Veteran Poster Featured Poster

A basic algorithm would be something like:

int temp = inputValue;
string roman = String.Empty;
while (temp > 999)
{
  roman += "M";
  temp -= 1000;
}
while (temp > 899)
{
   roman += "CM";
   temp -= 100;
}
while (temp > 499)
{
   roman += "D";
   temp -= 500;
}
while (temp > 399)
{
   roman += "CD";
   temp -= 100;
}
while (temp > 99)
{
   roman += "C";
   temp -= 100;
}
while (temp > 89)
{
   roman += "XC";
   temp -= 10;
}
// and so on...

There are probably more efficient ways of doing it, but it gives you a general idea.

darkagn 315 Veteran Poster Featured Poster

Declare the variables value1 and value2 before the if-statements.

int value1 = 0;
int value2 = 0;
if (checkbox1.checked) // you don't need to say == true here
  value1 = 1000000;
if (checkbox2.checked)
  value2 = -392014;
int value3 = value1 + value2;
myFunction(value3);

//...

public void myFunction(int value3)
{
  // do something...
}

PS please use code tags, it makes posts much easier to read.

darkagn 315 Veteran Poster Featured Poster

Sorry I can't see anything wrong with your code, that's exactly how I would do it. I'm surprised that the compiler lets you get away with using the variable name var though, I thought var was a reserved word in C#. Have you tried stepping through your code and viewing the node attributes each time to make sure that the kv.Value is correct?

darkagn 315 Veteran Poster Featured Poster

Can you post your code of where you attach the Map attribute to the Variant node in your application?

darkagn 315 Veteran Poster Featured Poster

Not sure what you mean by the first one, but for 2, it is easier and more accurate to use an identity field in the database.