darkagn 315 Veteran Poster Featured Poster

Sorry I misunderstood what you were asking. You should be able to leave them uninitialised (ie blank), but you can't use them until after they have been assigned. You will need to move the line double grossPay = hoursWorked * payRate; and each of the tax calculation lines after the user input lines.

darkagn 315 Veteran Poster Featured Poster

You can use a WriteLine() to describe what you want the user to enter, then wait for their response using ReadLine(). You will need to make sure that the user has entered a number.

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

It's returning a value so it isn't a NonQuery

ExecuteNonQuery() should be correct for executing a stored procedure.

set @ReturnIDcount = '301A' + cast( @idcount as numeric)

I would say this line in your procedure is incorrect. You are casting @idcount to a numeric field and attempting to append to a varchar, and @ReturnIDcount is listed as datatype nvarchar(max). To be sure, wrap the cast in another cast to an nvarchar type like so:

SET @ReturnIDcount = '301A' + CAST(CAST(@IdCount AS NUMERIC) AS NVARCHAR(40))
darkagn 315 Veteran Poster Featured Poster

Remove the dbo. from the INSERT query. It thinks you are trying to call your procedure recursively rather than insert directly to the table Transactions. BTW naming is important in a database, and TRANSACTION is a special SQL word. Try using a more descriptive name for the procedure, such as CREATETRANSACTION which actually describes what the procedure does.

EDIT: Sorry, I misread your SQL. Can you post the code that calls this procedure, I am thinking that you have too many parameters listed for your execution.

darkagn 315 Veteran Poster Featured Poster

Hi weajane01 and welcome to DaniWeb :)

Your deletion query has the following where clause:
WHERE id=$id AND course=$course

Can you confirm that the tblstudent table in your database has a primary key on the id and course field? Any other fields in the table must be included in the where clause to ensure only one record is deleted. You can try a select statement first and see if it returns exactly 1 row before deleting.

darkagn 315 Veteran Poster Featured Poster

You can use a ParameterizedThreadStart delegate like so:

Thread workerThread = new Thread(new ParameterizedThreadStart(LongRunningOperation);
workerThread.Start(a, b);

However note that the parameters a and b are passed as objects, not as int's so you will need to cast them inside your method.

public static Double LongRunningOperation(object a, object b)
{
   if (a.GetType() != typeof(Int32) || b.GetType() != typeof(Int32))
     throw new ArgumentException("An error occurred with the type of arguments passed!");

   int aValue = Convert.ToInt32(a);
   int bValue = Convert.ToInt32(b);

   // do something meaningful here...
}
darkagn 315 Veteran Poster Featured Poster

You can use the RANK function to do this. Here is a link to MSDN's description of the function, and here is an excellent article that has some examples of its use.

Something like this will work for you, you may need to change the order to get the way you want it:

SELECT RANK() OVER (ORDER BY vcBidAmount, vcBidTime DESC) AS Ranking,
*
FROM BiddingTable

As an aside, it is not good to use VARCHAR fields for amounts of money, the sorting will be strange and it isn't truly representative of what type of data you are deailing with. For example, '100.3' comes before '2.7' in a string comparison, but obviously the number 100.3 > 2.7.

darkagn 315 Veteran Poster Featured Poster

Hi Dani and other administrators/moderators,

I have had little time recently to contribute to the site, but I noticed tonight that the number of members is fast approaching the 1 million mark - at the time of this post it is 952,959 members. At the current rate of new member signings, approximately when do you anticipate reaching the seven figure mark? It will be quite an achievement and I hope I am online when it happens so I can congratulate you all!

Cheers,
darkagn

darkagn 315 Veteran Poster Featured Poster

Hi wjperdue and welcome to DaniWeb

You have two where statements which is incorrect. What you need is a single where statement, with extra conditions OR'ed or AND'ed together, so:

WHERE HD_TICKET.HD_QUEUE_ID="6"
AND HD_TICKET.CREATED BETWEEN [Start Date] AND [End Date]
GROUP BY (HD_PRIORITY.NAME)

should be better. Change the first AND to OR if you want either condition to be true instead of both.

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

This exception indicates that you have made a call that requires a filepath, and you have specified one that is too long for it to handle. Can you post a short snippet of the code surrounding where the error is thrown, or the stack trace message for the error? Try printing out the fully qualified path of each file before you instantiate the DirectoryInfo class to the Console or a MessageBox.

According to this article the maximum filepath length in the Windows API is MAX_PATH (260 characters).

darkagn 315 Veteran Poster Featured Poster
  1. You could create your own Add method that passes through to the collection:

     public void Add(object item)
     {
       this.Items.Add(item);
     }
    
  2. The CheckListBox.ObjectCollection that is returned by the Items property is a public non-sealed class so in theory you can extend it:

    public class MyCheckListBox : CheckListBox
    {
      public class MyCustomCollection : CheckListBox.ObjectCollection // possibly needs to extend CheckListBox..::..ObjectCollection
      {
         // override whatever collection methods you need to here
      }
    
      // override the Items property of the CheckListBox to return your new collection type
      public new MyCheckListBox.MyCustomCollection Items { get; }
    }
    

but is that necessary?

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

Love the SQL injection joke!

darkagn 315 Veteran Poster Featured Poster

This reply may have come too late, but if you draw a graph of the execution of the function will produce 11 edges, 9 nodes and 1 exit point. First we step into a loop (looks like a triangle of nodes in the graph). The middle of the loop provides the starting point for the inner loop. The inner loop's central node forms the start of an if-statement (looks like a diamond in the graph). Plugging these values into the complexity formula, you will get 11 - 9 + (2*1) = 4.

darkagn 315 Veteran Poster Featured Poster

Environment.Exit() allows you to pass an error code integer like many console applications do when they complete their execution. Application.Exit() is probably the best method as this indicates that the application is complete without error. Both methods will terminate threads of execution and dispose of the memory objects cleanly.
I have never used Process.GetCurrentProcess().Kill() but I think this might not be enough to close an application in some circumstances?

EDIT: My earlier post listed Application.Close() -- this should be Application.Exit() - sorry for the confusion.

darkagn 315 Veteran Poster Featured Poster

Try Application.Close() or Environment.Exit(int) methods. this.Close() closes the form but doesn't shut down the application.

darkagn 315 Veteran Poster Featured Poster

You need to work out exactly which object is yet to be initialised by stepping through your code with the debugger. The code you have posted looks correct, I am guessing the error is actually occurring in the constructor for frmMain, or maybe that MainTool.frmmain is not set to the same instance of frmMain.

Application.Run(new frmMain(args[0].ToString()));

The above line of code creates a new instance of frmMain, so MainTool.frmmain is no longer pointing to the right place. A better way of doing it would be to create a string property in your frmMain class called Path and doing the following:

frmMain main = new frmMain();
MainTool.frmmain = main;
if (args != null && args.Length > 0)
    main.Path = args[0];
Application.Run(main);
darkagn 315 Veteran Poster Featured Poster

The args parameter to the Main function is a list of command line parameters. If I run the following command from a cmd prompt:

MyApplication.exe -e 5

Then args[0] will be set to "-e" and args[1] will be set to "5". Note that the arguments are strings already (since args is a string[]) so there is no need to convert them using ToString() method.

darkagn 315 Veteran Poster Featured Poster

My post in this thread is listed in my posts currently voted down, although the post score is 0. Not sure whether this is correct or not, but it is a bit confusing. I think the old terminology was posts currently negative?

darkagn 315 Veteran Poster Featured Poster

Probably not an urgent one but thought I'd point it out anyway, all of my old, deleted PM's are back and set to unread. Luckily I only have 27 to go through (27 in 4.5 years, can it be so few??). Also, I can't see anywhere to delete them?

darkagn 315 Veteran Poster Featured Poster

Most likely data is null. Can your method App.getGenericData return null and if so in what situation? Try wrapping the for-loop into an if-statement that reads if (data != null) and step through the code with the debugger to see what happens.

darkagn 315 Veteran Poster Featured Poster

Syndicate which was released earlier this year in the US was banned here in Australia as it failed to receive an MA15+ rating (we are yet to have an R18+ here, although it just passed Parliament today and is heading for the Senate for the final debate, but I digress...)

Obviously I haven't played it (although I loved the original, 1990's version of the game and can recall vaguely what the game is about). The game was refused classification for many reasons, but this link discusses many of the issues the censorship board had with the game, including:

"Combatants take locational damage and can be explicitly dismembered, decapitated or bisected by the force of the gunfire. The depictions are accompanied by copious bloodspray and injuries are shown realistically and with detail. Flesh and bone are often exposed while arterial sprays of blood continue to spirt from wounds at regular intervals"

and

"Civilians can be shot, accompanied by copious bloodspray, but it is not possible to decapitate or dismember them. It is noted that in cooperative play, points are awarded for civilian casualties"

If this is anything to go on I am guessing this is a pretty violent game, but like I say I haven't played it.

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

Ok so your aggregate functions are anything appearing in the SELECT part of the statement that SUM, COUNT, AVG, MAX, MIN etc etc over one or more columns. For example, in your SQL query:

select orders.orderid,orders.customerid,orders.orderdate,orders.shipcity,orders.shipcountry,
orderdetails.unitprice,orderdetails.quantity, SUM(orderdetails.unitprice*orderdetails.quantity )as total from orders
inner join orderdetails on orders.orderid=orderdetails.orderid group by orders.customerid

the SUM(orderdetails.unitprice*orderdetails.quantity) is an aggregate function. It aggregates (in this case sums) the function ( orderdetails.unitprice*orderdetails.quantity ) over all the rows. But it needs to know how to group the summing. That's where the GROUP BY clause comes in. Here's the golden rule of grouping:

Any column that is in the SELECT part of your query that is not in an aggregate function MUST be included in the GROUP BY comma-separated list.

Your query therefore needs to include the following columns in the GROUP BY clause:

orders.orderid,orders.customerid,orders.orderdate,orders.shipcity,orders.shipcountry,
orderdetails.unitprice,orderdetails.quantity

If you want to sum the orders by customer you would put customerid first in the list. So your query will look something like this:

select orders.orderid,orders.customerid,orders.orderdate,orders.shipcity,orders.shipcountry,
orderdetails.unitprice,orderdetails.quantity, SUM(orderdetails.unitprice*orderdetails.quantity )as total from orders
inner join orderdetails on orders.orderid=orderdetails.orderid group by orders.customerid, orders.orderid, orders.orderdate,orders.shipcity,orders.shipcountry,
orderdetails.unitprice,orderdetails.quantity

Have a play around with the order of the columns in that query, and try adding/removing columns and see how the aggregate result changes. You will soon discover how grouping affects the results.

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

I believe a minimal instance of MSSQL Server is installed with VS2008. You can download the express version of MSSQL Server though.

Here is a link to MSSQL 2008 R2 Server, you can google for MSSQL 2010/2012 Express versions if you prefer.

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

Hi tommyarcher and welcome to DaniWeb :)

Are you sure you want to use a stored procedure? Your sample looks like a simple query rather than a SP, which is defined like so:

CREATE PROCEDURE SelectVendors
(
   @VCode INT
)
AS
SELECT [V_NAME], [V_PHONE], [V_STATE] FROM [VENDOR] WHERE ([V_CODE] = @V_CODE)

This SP would be called in C# (sorry I don't know VB) like so:

SqlConnection cnn = new SqlConnection(connectionString);
cnn.Open();
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SelectVendors";
SqlParameter param = cmd.CreateParameter();
param.Name = "@VCode";
param.DbType = SqlDbType.Int32;
param.Value = 64;

// execute the stored procedure and return the data in a reader
SqlDataReader reader = cmd.ExecuteReader();
// generate a list of "Vendor" objects to hold the data
List<Vendor> list = new List<Vendor>();
while (reader.Read())
{
   Vendor v = new Vendor();
   v.Name = reader["V_NAME"].ToString();
   v.Phone = reader["V_PHONE"].ToString();
   v.State = reader["V_STATE"].ToString();
   list.Add(v);
}

// use list to do something useful
// ...
cnn.Close();

If you're not using a stored procedure, change the command type to CommandType.Text and set the command text to the query.

Hope this helps, good luck :)

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

Once you have created the Customers table, you can't create it again unless you DROP TABLE first. You can use an ALTER TABLE query to alter the column structure of a table without losing data.

Each INSERT statement can only accept one set of VALUES. You need to write three INSERT queries to insert your three rows of data.

darkagn 315 Veteran Poster Featured Poster

JavaScript is a scripting language used most commonly to handle events in a web page. JSON is not a programming language at all, it is more like XML in that it represents data in a structured manner. While you may use one or both of these in your project, I would suggest that the connection to the database would more likely involve PHP or ASP .NET or some other high-level language like that.

darkagn 315 Veteran Poster Featured Poster

One important use of overriding the ToString method in your classes is for consistency in the display of information in your views. It is far easier to override the ToString method than to remember the format used in each view for your class.

Say for example that I have a class called Employee. Let's say I want my employee record to always be displayed as first name followed by a space followed by the surname. Overriding the ToString method allows it to be performed in one place, while you may have several views containing employee information, say an employee list, a sales figures list and a graphical representation of their sales figures. To be consistent I would have to apply this formatting in three places rather than the one.

ddanbe commented: Well said! +15
darkagn 315 Veteran Poster Featured Poster

Is your web app a WCF service? If so, you can just configure your client to connect to the base HTTP endpoint address and it should all hook up so long as the service implements the same operation contract as the client is after.

If it's not a WCF service, I think you would be better off converting your client to a standard web client. In theory I suppose it could still connect to your URL in its configuration but it would probably take longer to try to work out than to port your code.

darkagn 315 Veteran Poster Featured Poster

So you want the GetEnumerator class to return the enumerator for your internal Stack object, varStack ? I would do this:

public IEnumerator<Move> GetEnumerator()
{
  if (varStack == null)
    return null;
  else
    return varStack.GetEnumerator();
}
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 the FileStream class. It has ReadBytes and WriteBytes methods that can be used to read and write bytes to a file. The code sample on this page is a bit simple, but Google the FileStream class and you will find plenty of examples.

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

Use a DateTimePicker with the Format set to Time.

darkagn 315 Veteran Poster Featured Poster

This is definately possible in WCF. The beauty of WCF is that the endpoint in the server can rely on TCP, HTTP or some other communication protocol and in order to change protocols you only have to manipulate the config file rather than the code itself.

But this doesn't mean that WCF is right for your project, it really depends on what you want to do and how you want to do it. The WCF model creates a Windows service that acts as your server in your scenario, and clients connect to it. This is probably perfect for you since you want it to run all the time, but that is really up to you.

So I guess you need to determine how things will be transported (TCP, HTTP, UDP etc), what format your data will be moved in (XML, CSV, JSON etc) and what exactly needs to be a client (Windows PC, IPhone, Android Tablet etc). These three key questions will help determine whether WCF is the right way to go, or whether you are better off implementing a more traditional client-server architecture.

darkagn 315 Veteran Poster Featured Poster

Most likely the manufacturer of the device will have some sort of API that allows you to talk to the device. Try their website or contact them directly for details.

darkagn 315 Veteran Poster Featured Poster

Err, the example link I gave was for using the interfaces mentioned in Visual C#. But if you google the IComparable interface I am sure you will find plenty of examples.

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

Read the text file records into an array or some other list data structure. Let's call it myList for this example.
Create a reference to the current record. Let's call it currentRecord for this example.
Create a reference (int) to the current record's index in the list. Let's call it currentIndex for this example.

Here is how I would write the First and Previous methods. Next is opposite of Previous and Last is opposite of First so I will leave them to you.

public void First()
{
  // make sure we can get the data
  if (myList.Count > 0)
  {
    // first index in the list is 0
    currentIndex = 0;
    currentRecord = myList[currentIndex];
  }
  else
  {
    currentIndex = -1; // -1 to indicate nothing selected
    currentRecord = null;
  }
}

public void Previous()
{
  // ensure we can get a previous record
  if (myList.Count > 0 && currentIndex > 0)
  {
     // decrement the current index and update the current record
     currentIndex--;
     currentRecord = myList[currentIndex];
  }
}
darkagn 315 Veteran Poster Featured Poster

Without knowing the details of your error, I would say that your connection string (conn) is incomplete. Here is a great reference site for constructing connection strings, but I would say that you may need to provide a Password or Integrated Security setting?

kvprajapati commented: Agree! :) +15
darkagn 315 Veteran Poster Featured Poster

I think that error code of 3241 indicates a backwards compatability issue. Are you sure the backup was created with the same or earlier version of SQL server than the one you are attempting to restore onto? Note that service packs can be applied to one instance and not the other, so make sure you have the latest SP installed on the instance you are restoring to (I think 2005 had a service pack 3 from memory, possibly more??)

Hope this helps :)