DdoubleD 315 Posting Shark

Well, you still left out the directories for the project (properties), but maybe I don't need it anyway. Here is how you would retrieve the record count from the Combo table where Naam='Hamer'... That is to say that I tested by passing in "Hamer" to the method.

public static int GetRecCount(string naam)
            {
                string database = @"c:\AccessDbs\Calaesto.mdb";
                string connParams = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}";
                string connStr = string.Format(connParams, database);

                OleDbConnection conn = new OleDbConnection(connStr);
                string SQLString = "SELECT Count(*) FROM Combo WHERE Naam = '" + naam + "'";

                try
                {
                    conn.Open();

                    using (OleDbCommand cmd = new OleDbCommand(SQLString, conn))
                    {
                        int rows = (int)cmd.ExecuteScalar();
                        return rows;

                    }
                }
                catch (OleDbException ex)
                {
                    Console.WriteLine("Exception: {0}\r\n   Stack Trace: {1}", ex.Message, ex.StackTrace);
                    System.Diagnostics.Debugger.Break();
                }
                finally
                {
                    conn.Close();
                }
                return -1;
            }
DdoubleD 315 Posting Shark

Lol, oops
Here's the update

That was quick! Hey, I just looked at the DB, and I noticed there are only two columns in the Combo table: ComboId and Naam... Is that how it is supposed to be?

DdoubleD 315 Posting Shark

Here are the Project file and the database.

Yep, just the project file (".csproj") and the mdb ;)... Cannot really use the project file by itself; you need to include the source files (*.cs, etc.) too. Sorry about the miscommunication... when we say zip up the project, we mean the "whole" project. I will wait for your updated attachment.

DdoubleD 315 Posting Shark

No worries... Looking at that example, it looks ok to me on the surface except for the line: da.SelectCommand cmd = new SqlCommand("GetAllAuthors", sqlConn); , which I don't think will compile with the "cmd" segment...

DdoubleD 315 Posting Shark

Here is a crude example of what you wanted, but with only a few of the methods and with the code guts removed. After responding to your new thread, I decided to put together the sample you were looking for. If this answers you original question in this thread, go ahead and mark as solved and we can continue to work out any details in the other thread. I went ahead and used a DataTable object for the table's records to further elaborate on what I was telling you in the other thread too...

class DataAccessLayer
            {
                public static DataTable GetAuthorTable()
                {
                    // dao/db code here to get the records
                    // ...
                    DataTable authorTable = new DataTable();
                    // Fill above with records from dao/db code...

                    // return the records of the Author table
                    return authorTable;
                }
                public static void UpdateAuthor(DataRow authorRecord)
                {
                    // dao/db code here to update the records
                }
                public static void InsertAuthor(DataRow authorRecords)
                {
                    // dao/db code here to insert the record
                }
                public static void DeleteAuthor(int authorId)
                {
                    // dao/db code here to delete the record
                }
            }
            class BusinessLogicLayer
            {
                DataTable authorTable = null;

                public void LoadAuthorTable()
                {
                    // Load records from DAL table...
                    authorTable = DataAccessLayer.GetAuthorTable();
                }

                public string [] GetAuthorNames()
                {
                    if (authorTable == null)
                        LoadAuthorTable();

                    // Load an array of author names to return to our GUI...
                    string [] authorNames = new string[authorTable.Rows.Count];
                    int ndx = 0;
                    foreach (DataRow dr in authorTable.Rows)
                    {
                        authorNames[ndx] = (string)dr["Name"];
                        ndx++;
                    }
                    return authorNames;
                } …
DdoubleD 315 Posting Shark

Yes, that's good that you are separating the code. However, in order to tell you how to convert a DataSet or rather your empDataSet to populate your Employee [] employees , I still need to know how each is defined.

For the "empDataSet", I assume that contains records from an Employee table or something, but I don't know what the table columns are...

For the Employee type, I assume it contains members that represent the DB columns from 'Employee' table, but I don't know what these fields are either...

I would like to mention though, that if your DAL is populating the DataSet with records that will match the structure of your Employee type, you might achieve the end result without any needed conversion at all between the DAL and the BLL because if your BLL expects a table containing columns with particular names, you can simply use the returned DataSet's Tables[0], which is a DataTable that can be accessed by column name such as: empDataSet.Tables[0].Rows[0]["Lastname"]; , which would give you the table's 1st row value for column "Lastname" if that is what it is called. Of course this code should be broken out to make it less cryptic, but I just wanted to demonstrate that you might not need to do any conversion from DataSet to a separate Employee [] type.


Example of breaking down the empDataSet.Tables[0].Rows[0]["Lastname"]; mention above:

// Retrieve reference to the Employee table from DataSet...
                DataTable dt = empDataSet.Tables[0]; …
DdoubleD 315 Posting Shark

More information is needed:

1) structure of Employee
2) structure/contents of the DataSet returned by: DataBaseLayer.GetAllEmployees();

DdoubleD 315 Posting Shark

if you want it to be accurate, you need to calculate up front the total items to be processed (scanned?), then divide into total items already processed * 100....

Here is an example of using BackgroundWorker with file copies in which the total number of bytes of all files to be copied are determined up front, then progress determined by bytes processed thus far: http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/a285bdb9-6838-48f3-b8ed-1bf0156f8c51/ Scroll down to the 1st post/reply by "NoBugs"

Here is an excerpt from that post where the author both: 1) builds list of files to process, and 2) calculates number of bytes that will be processed:

// Create list of files to copy
      string[] theExtensions = { "*.jpg", "*.jpeg", "*.bmp", "*.png", "*.gif" };
      List<FileInfo> files = new List<FileInfo>();
      string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
      DirectoryInfo dir = new DirectoryInfo(path);
      long maxbytes = 0;
      foreach (string ext in theExtensions) {
        FileInfo[] folder = dir.GetFiles(ext, SearchOption.AllDirectories);
        foreach (FileInfo file in folder) {
          if ((file.Attributes & FileAttributes.Directory) != 0) continue;
          files.Add(file);
          maxbytes += file.Length;
        }
      }
DdoubleD 315 Posting Shark

I followed your suggestion using MDIParent VS default and changed my idea of use a lot child form in sequence. I will perhaps use panels or tabs, then hide or visible to false.

Only a little question, using MDIParent VS default which is the best way to create the form options (like menustip>Options>Configuration, then display a form) to interact to the childform? Create a winform without being child, then use "get and set"?

Thanks!

>>using MDIParent VS default which is the best way to create the form options (like menustip>Options>Configuration, then display a form) to interact to the childform?

The menu that it generates contains items that represent common menu features found in MDI applications. You can add/remove them to suit your own needs.

>>Create a winform without being child, then use "get and set"?

You may not want to use a MDI approach to what it is you are doing. Because of the way you were trying to implement the Form.MdiParent , I thought I should direct you to the "shell" Windows Form item type that you could add to your project that gives an idea of how to interact with a MDI Parent.

Here is a link to MSDN MDI programming...

It is not clear to me what the purpose of your application is, so I don't want to recommend one way over another. However, using the MdiParent property as you were attempting to do for each form without maintaining a …

DdoubleD 315 Posting Shark

I would learn both if I were you. I programmed in C/C++ for several years, and I will tell you that once I started coding in C#, I really don't like looking at C/C++ code anymore, but I can and do mostly for code conversions...:)

As far as which one is the future, I think C# is the way to go, but by having a C/C++ knowledge base you will be more valuable as there are huge amounts of legacy code out there that need to be converted and interfaced with; and, I believe the job market still favors C/C++ because of this huge weight.

If you decide that you like C/C++, don't fret, because there is and will be for a long time much code and work out there using this language. However, if you are like me and most others, once you get on the C# bandwagon, you won't want to get off!

Cheers!

DdoubleD 315 Posting Shark

An MDIParent container paradigm has only one MDI parent, but you are using the MdiParent property for each successive form, which leaves the MdiParent property reference "dangling" if you close one of those forms, and also defeats having a Parent control...

I'm not sure, but it looks like you are trying to create an MDI Form from scratch? Did you know that there is an "MDI Parent Form" option from the VS -> Add New Item -> Windows Forms dialog? If you use this option to create an MDIParent Form, it will generate a lot code in the parent form, and you will see a method that looks like this, which gets called when you open a new form/document:

private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();
        }

If you really want to stick with how you are doing it, I can provide you a solution, but I'd rather make sure I'm not helping you find your way down the wrong path--if you know what I mean.

Let me know...

Be sure to read the above consideration. However, I got bored and made modifications to allow you to access any open form, but it will only work with one instance of each of your forms (eg. not two Form2 objects existing at the same time, etc.). There are a g'zillion ways to achieve something like this, and I usually try something different every time it comes up.;) …

DdoubleD 315 Posting Shark

An MDIParent container paradigm has only one MDI parent, but you are using the MdiParent property for each successive form, which leaves the MdiParent property reference "dangling" if you close one of those forms, and also defeats having a Parent control...

I'm not sure, but it looks like you are trying to create an MDI Form from scratch? Did you know that there is an "MDI Parent Form" option from the VS -> Add New Item -> Windows Forms dialog? If you use this option to create an MDIParent Form, it will generate a lot code in the parent form, and you will see a method that looks like this, which gets called when you open a new form/document:

private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();
        }

If you really want to stick with how you are doing it, I can provide you a solution, but I'd rather make sure I'm not helping you find your way down the wrong path--if you know what I mean.

Let me know...

DdoubleD 315 Posting Shark

I don't see anything right away that would prevent you from accessing that property. Can you zip up and attach your project?

DdoubleD 315 Posting Shark

But how I call in Fom3 for form1?

If i try to type form1.Text** any reference appears to the public string in form1...

Not sure what you mean. Are you still casting your form3.MdiParent to get your form1 reference? eg:

// in form3...
    Form1 form1 = (Form1)form3.MdiParent;
DdoubleD 315 Posting Shark

In form1, you have defined a get property setter to retrieve the string value, which you can do from form3. However, if you want to set the value of the textbox control on form1 from form3, you need to create a setter set property too. The typical way to do this is to combine the properties as:

// in form1 class, define property (I called it TextBox1):
        public string TextBox1
        {
            get { return textBox1.Text; }
            set { textBox1.Text = value; }
        }

        // then, in form3 to set the value of form1.textBox1.Text:
        form1.TextBox1 = "some text";
        // or, to get the value in form3:
        string text = form1.TextBox1;
DdoubleD 315 Posting Shark

You are most welcome...Cheers!

DdoubleD 315 Posting Shark

It's really a simple concept once you get a grasp on why you want to do this. Although you might have already considered this, I would expand the design to ensure that the presentation layer is also separated.

The idea is to reduce the overall maintenance and increase the scalability of your application. For instance, by putting the data access layer into its own division, you don't have to touch the business layer should you decide to incorporate a new database, or you decide to use another database altogether. Same thing goes for the presentation layer, because if you decide to switch to some other GUI you will find it much easier if you have not embedded your business logic (methods) inside the form code...

For the functions you have listed, most of the methods should go into the business layer even though these methods represent what you are wanting to achieve with your form presentation. However, you can easily call these business objects (classes and methods) from the form code to achieve the desired outcome and maintain separation.

For the data access layer, that is where you want you OleDb, Sql Server, MySql, or other data access specific code to be contained. This data access layer would be called upon by your business layer to manipulate data to and from the database.

That is a very simple, high-level, overview of good object layer-separation.

DdoubleD 315 Posting Shark

This is a pretty good article as far as comparing Windows Forms to WPF at a high level: DECIDING WHEN TO ADOPT WINDOWS PRESENTATION FOUNDATION

To find examples of some technologies you are interested in, try looking on CodeProject.com and CodePlex.com.

Geekitygeek commented: really informative article :) +1
ddanbe commented: Yes, nice article! +5
DdoubleD 315 Posting Shark

Thanks a lot. This does solve the problem of passing unspecified number of arrays. I've never used a foreach loop before, and with the example that has been provided it would write one array per line. However, what I'm trying to do is write a value from each array next to each other. Is there a way to index the object array that is passed? Thank you all for you help this far.

Not sure what you mean, but here is the for/next index version with the arrays accessed by index:

public static void ProcessArrays2(params object[] v)
        {
            // for each array in variable arguments...
            for (int i=0; i<v.Length; i++)
            {
                Array ary = (Array)v[i];

                // for each item in this array...
                for (int ii=0; ii<ary.Length; ii++)
                {
                    Console.Write(ary.GetValue(ii));
                    Console.Write(",");
                }
                // Separate each array with newline:
                Console.WriteLine();
            }
        }
DdoubleD 315 Posting Shark

I choose option B :P
I will send you the code, but I prefer to send I through a private message. I also send you the MSA database in question as an attachment.

OK, I'll be looking for the attachment in the thread per your PM.

DdoubleD 315 Posting Shark

Hey there, I'm still not sure what you are asking because I asked a couple of different questions, and I'm not sure which one you accepted as your issue.:D Select a choice:

A) Are you trying to ensure that the "combine" table only has distinct values for two of the columns when the records are selected and inserted from the other three?

B) Or, are you only wanting to perform a query on the "combine" table (after it has been built) to determine if it has a row containing certain values for two of the columns?

In either case, and in order to expedite potential solution, please include the SQL statement(s) you are using to build the "combine" table.

DdoubleD 315 Posting Shark

Create a public method in your Form1 to access the control's text, then from the child form, just up-cast your MdiParent to Form1 and access the method:

// defined in Form1, or the MdiParent form...
        public void SetStatusLabelText(string s) 
        {
           toolStripStatusLabel.Text = s;
        }

        // to call from child form:
        MDIParent1 parent = (Form1) this.MdiParent;
        parent.SetStatusLabelText("some text for the status bar...");
DdoubleD 315 Posting Shark

Not a problem. Please mark thread as solved if your question has been answered--thanks.

DdoubleD 315 Posting Shark

It´s only to design user permissions into the menu.. my newbie idea is to pass user textbox value from login form and in other forms make a if cicle to check which user is and then disable or enable the menu items... it´s work? Can have some consequence? failure?

The most simplest would be how you indicated you were thinking of doing it, but that limits your design to predefined usernames you evaluate in your if statements (at least as I understood you to say). If you do it like this, I would still define levels of access (levelUser and levelAdmin for example) and then set the menu items accordingly rather than have two or more separate code blocks that manipulate all the menu items in each block for each user...

A simple approach would be to create a table to store each user and menu identifiers for each menu option, as a boolean field switched on or off (true/false) to indicate whether the user has permission or not (menu item enabled or disabled).

Another simple, perhaps simpler, approach would be to create a table to store each user with a corresponding access level (some enumeration of values like: level0, level1, etc.), then use the level of access to determine whether the user has permission or not (menu item enabled or disabled), depending on what level of access is required to access that menu item.

As a more complex approach, you may wish to do both in …

DdoubleD 315 Posting Shark

Good point about that connection and stuff .
I already made an app in C# using MSA (which is MS Access) to alter a database and showing that database in a datagrid.
That database is the same that I'm using now.
The database consists 4 tables (items_1, items_2, combo, combine) and the first 3 tables mentioned have the columns (tablename)Id and Name.
The combine-table has the following columns:
Id, comboId, itemId_1, itemId_2

What I want is that I fill in 2 Names (from the items_x tables) and that my database checks if those 2 Names are use in 1 row in the combine-table.
What's needs to be done then, I already know.

I cannot tell from your last line whether you have already solved your problem. If so, please mark the thread as solved. If not, I will try to determine more clearly what it is you are asking...

Are you trying to ensure that the "combine" table only has distinct values for two of the columns when the records are selected and inserted from the other three?

Or, are you only wanting to perform a query on the "combine" table (after it has been built) to determine if it has a row containing certain values for two of the columns?

Or, have I missed completely what it is you want?:(

DdoubleD 315 Posting Shark

Are you asking how to find particular menu items, and then enable/disable menu items? Or, is your question more general about how to design user permissions into the menu design?

DdoubleD 315 Posting Shark

Hi,

No excuses: my problem is that I can't get my code to check if a certain record exists in a MSA database.

My code needs to check if the database contains a row where 2, 3 or 4 specified fields exist.
But, as mentioned, at the moment it only gives errors about missing parameters.
Before I post the code I'd like to know what the correct way is, as the code is very secret :).

Very secret...OK :cool: Here is an example of getting a count of records meeting a specific ID in a where clause:

using (OleDbConnection conn = new OleDbConnection(connStr))
                {
                    try
                    {
                        conn.Open();
                    }
                    catch (Exception Ex)
                    {
                        MessageBox.Show(Ex.Message);
                        System.Diagnostics.Debugger.Break();
                    }

                    string cmdStr = "Select count(*) from customers where id = 4";
                    OleDbCommand cmd = new OleDbCommand(cmdStr, conn);
                    int count = (int)cmd.ExecuteScalar();
                }
DdoubleD 315 Posting Shark

Try this for your functions.dll: Register .NET assembly...

DdoubleD 315 Posting Shark

C:\test\app.exe
C:\plugin.dll
C:\functions.dll
It doesn't work.

In the above scenario, have you tried running the app with "C:\" in your PATH environment settings?

It's not clear to me how your app is able to find and load the plugin.dll, but not the other. Could it be that the plugin.dll is registered and windows knows where to find; whereas this is not true for the functions.dll?

DdoubleD 315 Posting Shark

You might want to take a look at this thread: http://www.daniweb.com/forums/thread215125.html

It's a little lengthy, but if you don't find what you need in there at least it might help to explain better what you are looking for.

DdoubleD 315 Posting Shark
DdoubleD 315 Posting Shark

I suppose the main thing you are giving up is streamlined maintenance and scalability since you will need to manually copy and paste (or perhaps remove) segments of code anytime the size of the container gets changed.

Why are you avoiding loops?

DdoubleD 315 Posting Shark

If I want to create the file (text file) in the current folder where my exe is running, how should I pass the file name argument in filestream instantiation?
Thanks
Roy Thomas

Hi Roy. If you pass in just the filename (no path), the file will be created in the same folder as where your application is running, which is the current working directory. The only caveat to this is, if your application's process changes the current working directory.

ddanbe commented: Clear explanation. +5
DdoubleD 315 Posting Shark

Check the command text/query pass into the SqlCommand , which is what it is complaining about, but error doesn't show until you execute the command with ExecuteNonQuery :

//
        // Summary:
        //     Initializes a new instance of the System.Data.SqlClient.SqlCommand class
        //     with the text of the query and a System.Data.SqlClient.SqlConnection.
        //
        // Parameters:
        //   cmdText:
        //     The text of the query.
        //
        //   connection:
        //     A System.Data.SqlClient.SqlConnection that represents the connection to an
        //     instance of SQL Server.
        public SqlCommand(string cmdText, SqlConnection connection);
DdoubleD 315 Posting Shark

Not a problem! Please mark as solved--thanks!

DdoubleD 315 Posting Shark

Problem is that in your string ("22.925507, 0.0000000, 0.0000000, "), the Split has created a last item equal to a " " (space char), which the Convert.ToDouble(" ") yields the exception.

To correct, remove the trailing (last) comma.

As an alternative, change line 20 (or similar check for spaces) to be:

if (num != null && num.Trim().Length > 0)

You might also want to put your index increment for numline ("i++") to be inside the if block so it only gets incremented when your num is actually put into the numline array:

if (num != null && num.Trim().Length > 0)
                    {
                        numline[i] = Convert.ToDouble(num);
                        i++;
                    }
DdoubleD 315 Posting Shark

Sorry, I got distracted before I could correct the last post... This should work:

public static void Test()
        {
            int[] intAry = { 1, 2, 3 };
            string[] strAry = { "1", "2", "3" };
            double[] dblAry = { 1.0, 2.0, 3.0 };
            ProcessArrays(intAry, strAry, dblAry);
        }
        public static void ProcessArrays(params object[] v)
        {
            // for each array in variable arguments...
            foreach (Array ary in v)
            {
                // for each item in this array...
                foreach (object o in ary)
                {
                    Console.Write(o);
                    Console.Write(",");
                }
                // Separate each array with newline:
                Console.WriteLine();
            }
        }
DdoubleD 315 Posting Shark

?Is it possible to use it to pass an unspecified number of arrays of objects?
Yes you can do this.

void methodName(params object []v){
   ...
  }

adatapost pretty much gave you the way to do this. Here is an example of manipulating the variable arguments of object should you pass a variable number of arrays:

void methodName(params object[] v)
        {
            // treat each (variable) argument as an array...
            foreach (object[] ary in v)
            {
                // process the current array argument...
                foreach (object o in ary)
                {
                    Console.Write(o);
                    Console.Write(","); // delimiter for each item "o" in array...
                }
                // Separate each array with newline:
                Console.WriteLine();
            }
        }

I didn't actually test the above code, but it does compile.

EDIT: there is a casting exception with the above....

DdoubleD 315 Posting Shark

If you intend to parse or convert the byte[] into its string equivalents, the StreamWriter should work fine as long as long as it does not need to be thread safe. For thread safety, look at TextWriter .

If you just want to write the byte[] to a file, look at FileStream class.

If you intend to parse the byte[] array into various types, consider using the BinaryWriter class.

Geekitygeek commented: clear and concise :) +1
DdoubleD 315 Posting Shark

I tested that code to insert the sheet data into the Access table, and I didn't find a problem with it. I made some minor modifications to make it a little more flexible and to provide a more accurate error message on failure.

This method combines the SELECT from the Excel sheet and INSERT into the Access table into one command:

public static void ImportSpreadsheet(string fileName, string sheetName)
            {
                string excelConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;"
                    + @"Data Source=" + fileName + ";"
                    + "Extended Properties=Excel 8.0;";

                // set the Access table name to import the sheet into...
                string tableName = sheetName;

                using (OleDbConnection conn = new OleDbConnection(excelConnStr))
                {
                    try
                    {
                        conn.Open();

                        using (OleDbCommand cmd = new OleDbCommand())
                        {
                            cmd.CommandText = @"SELECT * INTO [MS Access;Database="
                                + accessDatabase + "].["
                                + tableName + "] FROM ["
                                + sheetName + "$]";

                            cmd.Connection = conn;

                            cmd.ExecuteNonQuery();
                        }
                    }
                    catch (DbException ex)
                    {
                        Console.WriteLine("Exception: {0}\r\n   Stack Trace: {1}", ex.Message, ex.StackTrace);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }

Give it a try and mark the thread as solved if there is no problem.

DdoubleD 315 Posting Shark

The first thing you need is a database--do you have one? Then, you need to build a proper connection string to connect to it with: http://www.connectionstrings.com/. How you proceed from here depends on the database type, but the basic, most common stuff, involves:

1) Opening a connection
2) Building a SQL command
3) Executing the command

There are infinite examples on the web, but if you cannot find some really "basic" examples for your database type, let us know what DB you are using and I'm sure we can point you to a few.

Cheers!

ddanbe commented: informative +5
DdoubleD 315 Posting Shark

Good morning avirag (for me at least). Things are never quick and easy with you my friend. Anyway...

I wrote an ADO COM interface earlier this morning to dynamically build the Access table from a DataTable that I loaded from my spreadsheet data using the method I supplied you with yesterday. Typical morning of fun for me I suppose because I hand't tried doing this with ADO COM before. I already have a database wrapper that builds the SQL commands dynamically to do this, but I was curious about any shortcuts using ADO COM. I got it to work with a few field types, but for it to be complete, I would need to build a wrapper around it too. So, I decided to further my search...

While beginning a search to find other ways this could be done, I found that code you are using to create your Access database in your example code you gave:

Link: http://www.dotnetspider.com/forum/187304-Using-C-how-import-excel-file-into-ms-access-database-dynamic-table.aspx

Remaining code from link you are missing in your example code:

OleDbCommand _command = new OleDbCommand();

                _command.Connection = _connection;

                try
                {

                    _command.CommandText = @"SELECT * INTO [MS Access;Database=C:\Book.mdb].[Sheet1] FROM [Sheet1$]";

                    _connection.Open();

                    _command.ExecuteNonQuery();

                    _connection.Close();

                    MessageBox.Show("The import is complete!");

                }

                catch (Exception)
                {

                    MessageBox.Show("Import Failed, correct Column name in the sheet!");
                }

Why didn't you use that remaining code to SELECT the SHEET into the database? Does it not work or something?

DdoubleD 315 Posting Shark

Ignorant of the subject am I (definately not my forte) , but it sounds like you might need to write your own device driver to emulate the device. I might not be giving you any information here you haven't already considered; however, I ran across these links and figured I would pass them on:

Forced FeedBack...

Capture directinput device...

What you might also look for is a keyboard/joystick emulator, that could provide more insight into directly communicating with and emulating the driver interface.

DdoubleD 315 Posting Shark
DdoubleD 315 Posting Shark

What is the code you have so far for writing to your Access table?

EDIT: Did you test the code I gave you to determine it satisfies your import of the worksheet?

DdoubleD 315 Posting Shark

It is not clear to me what you are doing with this line and how you want it to expand and shrink. Can you provide the code with comments, or some images that represent the desired outcome?

DdoubleD 315 Posting Shark

avirag, this will import your excel data into a DataSet. If you need additional help writing the DataSet to Access table, please create another thread. Play with this and see if it works for you...

// NOTE: adaptor always returned error without full path of .xls file
                string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                    @"Data Source=c:\ExcelData\stockdata.xls;" +
                    "Extended Properties=Excel 8.0;";
                
                // Metals is the sheetname...
                string query = "SELECT * FROM [Metals$]";

                DataSet ds = new DataSet();

                using (OleDbConnection conn = new OleDbConnection(connStr))
                {
                    try
                    {
                        conn.Open();

                        using (OleDbDataAdapter cmd = new OleDbDataAdapter(query, connStr))
                        {
                            cmd.Fill(ds, "StockData");
                            return ds;
                        }
                    }
                    catch (OleDbException ex)
                    {
                        Console.WriteLine("Exception: {0}\r\n   Stack Trace: {1}", ex.Message, ex.StackTrace);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
DdoubleD 315 Posting Shark

Wow is right! As Ryshad suggested, you could do this without the array altogether. However, if you must use an array as part of the requirements, I would suggest using an array to represent the monetary denominations instead of a 1 to 1 representation of 0.00 - 1.00. For example:

int[] denominations = 
            {
                1, // pennies
                2, // two pence
                5, // five pence
                10, // ten pence
                20, // twenty pence
                50 // fifty pence
            };

You could then incorporate that array with the modulo loop that Ryshad suggested to allocate each of the denominations.

Also, and as a side note, if you were to incorporate this array design and pass it into a method that uses the modulo loop design with the given array, your coin buckets could be made to be country/coin independent. However, you might need to make some adjustments to your form to make it independent as well. I wouldn't worry about this right now, but a way of thinking you can ponder a little...

Cheers!

DdoubleD 315 Posting Shark

You edited your post after I provided a solution to a potential problem, which makes this thread more confusing...

Why did you use s.Length to allocate the array instead of just new int[s] in your constructor? You are looping through "n", or "s" in this case, not the length of an "int"!

Also, include the error message you are getting, which will help narrow down your problem too...

EDIT: You also introduced a new error by trying to access int s as an array in your posted change:

arr[i] = Convert.ToInt32(s[i] - 48);
DdoubleD 315 Posting Shark

Why do you want to reuse these id's once deleted--why does it matter? I would suggest that if your code is dependent upon id's being in consecutive order and gap free, that you might have a design flaw to begin with.

If you are insistent upon pursuing this, check out this blog: http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/