Mike Askew 131 Veteran Poster Featured Poster

One clarification, in the edit code:

        private void btnOrderEdit_Click(object sender, EventArgs e)
        {
            int i, j;
            i = dataGridView2.CurrentCell.RowIndex;
            j = dataGridView2.CurrentRow.Index;
            System.Data.OleDb.OleDbCommandBuilder cb;
            cb = new System.Data.OleDb.OleDbCommandBuilder(cashDA);
            DataRow dRow2 = cashOrdersDS.Tables["cashOrders"].Rows[0];
            dRow2["cashQTY"] = Int64.Parse(txtOrderQTY.Text);
            dRow2["cashDescription"] = txtBoxDescrip.Text.ToString();
            dRow2["cashSupplier"] = txtBoxSupplier.Text.ToString();
            dRow2["cashDate"] = dateTimePicker1.Value.ToString();
            dRow2["cashCost"] = Convert.ToDouble(txtBoxCost.Text);
            dRow2["cashSell"] = Convert.ToDouble(txtBoxSell.Text);
            dRow2["cashAccountRef_FKID"] = Int64.Parse(textBox1.Text);
            /// ###########################################################
            /// Re-added dRow2 to the dataset after population else it does absolutely nothing, change #8
            /// ###########################################################
            cashOrdersDS.Tables["cashOrders"].Rows.Add(dRow2);
            /// ###########################################################
            /// Added connection open and close around the update call, change #9
            /// ###########################################################
            cashCustom.Open();
            cashDA.Update(cashOrdersDS, "cashOrders");
            cashCustom.Close();
            MessageBox.Show("Data Updated");
        }

On line 8 it sets dRow2 to a specific row (always the first in table) is this intentional? As surely it will always just edit that one entry. Should it not be off a selected index or something?

Mike Askew 131 Veteran Poster Featured Poster

ahh thank you it works fine now :) but one question? if i copy the original
CardsNumber = Cards;
CardsNumber = myObject.HandleString(CardsNumber);
and then only use the copy in the method i had earlier should'nt that give the same effect? just want to know :)

It would provide the same effect yes.

Mike Askew 131 Veteran Poster Featured Poster

Well what have you got so far for this?

Attempt it yourself and we will correct you when you run into trouble, specially when it sounds like homework.

Mike Askew 131 Veteran Poster Featured Poster

You may need to tweak my variable declaration to get the length right, but you were overwriting the originals passed in as well as returning them to the new array as output.

public string[] HandleString(string[] str)
        {
            string[] TheResults = new string[str.Length];
            for (int a = 0; a <= 51; a++)
            {
                TheResults[a] = str[a];
                TheResults[a] = TheResults[a].Replace("   Hjärter ", "");
                TheResults[a] = TheResults[a].Replace("   Ruter ", "");
                TheResults[a] = TheResults[a].Replace("   Spader ", "");
                TheResults[a] = TheResults[a].Replace("   Klöver ", "");
            }
            return TheResults;
        }
Mike Askew 131 Veteran Poster Featured Poster

If myObject.HandleString(Cards); has a return value, CardsNumber = myObject.HandleString(Cards); will set CardsNumber to be that value.

Cards would be modified if it is a form level variable and the method makes changes to the Cards variable within it.

Can we see the method code and that might help find the change that you dont want.

Mike Askew 131 Veteran Poster Featured Poster

Off the top of my head im afraid not, I usually just use the standard DataSet/DataAdapter to get information and its performance is fine.

Mike Askew 131 Veteran Poster Featured Poster

The following suggestions will help the process of answering threads in the most efficient manner.

  1. Do not hijack other member's threads, you will not get replies, instead start your own question.

  2. What have you tried? We are not here to mock mistakes and showing effort made will make us more inclined to help you than simply posting your issue and expecting us to fully code it for you.

  3. Provide the XML you are working with, or a snippet of it, it is time consuming and counter-productive to generate test XML.

  4. Provide the expected output XML, a copy of the actual output you would expect from the snippet of input XML is an underestimated help tool when creating solutions to the problems.

  5. Clearly explain what is required, transformations in particular can be complex and so clarity of what is required will reduce unnecessary delays/clarification.

  6. Namespaces, if your XML uses them and the snippet does not show this please inform us, they will change the outcome of some transformations when we don't know about them.

Happy posting!

Mike Askew 131 Veteran Poster Featured Poster

We might be able to help, if we can see the code we are dealing with. As Console.Beep(); works fine for me.

Mike Askew 131 Veteran Poster Featured Poster

Stultske is right, mess with cracked programs and make sure your up the task of dealing with the consequences.

Mike Askew 131 Veteran Poster Featured Poster

Most likely using the standard provided classes microsoft have. and writing SQL that doesnt select redundant data, will be the fastest way in my opinion.

Mike Askew 131 Veteran Poster Featured Poster

You have two options to convert a string to an integer, convert and tryparse.

string TempString = 0;
int OutInt = Convert.ToInt32(TempString); // This will exception if not viable to convert to integer

string TempString = 0;
bool Success;
int OutInt;
Success = int.TryParse(TempString, out OutInt); // This will return true if the convert was successful and false if it wasn't but will NOT exception and is generally the better practice.
Mike Askew 131 Veteran Poster Featured Poster

I have made some changed to your code, highlighted with triple comment blocks surrounded with #'s.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CardIndex_v2_2012
{
    public partial class Form1 : Form
    {
        private ADODB.Connection adoConn = new ADODB.Connection();
        private ADODB.Recordset adoRS = new ADODB.Recordset();
        //Access Database Adapater Information//
        System.Data.OleDb.OleDbConnection cashCustom = new System.Data.OleDb.OleDbConnection();
        System.Data.OleDb.OleDbDataAdapter cashDA = new System.Data.OleDb.OleDbDataAdapter();
        //Data Sets and Data Tables//
        /// ###########################################################
        /// Removed the now-redundant data tables and an unused private dataset, change #1
        /// ###########################################################
        DataSet cashCustomersDS;
        DataSet cashOrdersDS;
        DataSet printedCustomersDS;

        public Form1()
        {
            InitializeComponent();
            //Opens Line 50 Connection//
            adoConn.Open("SageLine50v17", "Manager", "", 0);
            adoRS = adoConn.OpenSchema(ADODB.SchemaEnum.adSchemaTables, null, System.Reflection.Missing.Value);
            while (!(adoRS.EOF))
            {
                comboBox1.Items.Add(adoRS.Fields["TABLE_NAME"].Value.ToString());
                adoRS.MoveNext();
            }
            adoRS.Close();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //Code Below Disables all Txt Boxes from Being Selected until a new account is ready to be inputted//
            txtBoxAccRef.Enabled = false;
            txtBoxAddr1.Enabled = false;
            txtBoxAddr2.Enabled = false;
            txtBoxCounty.Enabled = false;
            txtBoxName.Enabled = false;
            txtBoxPostCode.Enabled = false;
            txtBoxTown.Enabled = false;
            txtOrderQTY.Enabled = false;
            txtBoxDescrip.Enabled = false;
            txtBoxSupplier.Enabled = false;
            dateTimePicker1.Enabled = false;
            txtBoxCost.Enabled = false;
            txtBoxSell.Enabled = false;
            cashOrdersTable.TableName = "cashOrders";
        }
        private void radioBtnCash_CheckedChanged(object sender, EventArgs e)
        {
            //Following Code loads CashCustomers data Table from Database and puts into dataGridView1//
            cashCustom.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Orders.mdb";
            /// ###########################################################
            /// Removed the data table and created it directly into the dataset and updated bindings accordingly for dataset, change #2
            /// ###########################################################
            cashCustomersDS = new DataSet();
            cashCustomersDS.Tables.Add("cashCustomers");
            cashCustom.Open();
            String cashCustomerSQL = "SELECT * FROM cashCustomers"; …
Mike Askew 131 Veteran Poster Featured Poster

Umm you can use the First_Name.TextChanged event and check if the length of the textbox string is over 0, if so enabling the search button, else disabling it.

Mike Askew 131 Veteran Poster Featured Poster

Mod, by earning the management teams respect and trust, along with other factors most likely.

Admin, can't say I know.

Mike Askew 131 Veteran Poster Featured Poster
string update_sql = "UPDATE Customers SET Last_Name = '" + col2 + "', Type_Of_Trip = '" + col3 + "', Leaving_From = '" + col4 + "', Going_To = '" + col5 + "', Departing_Date = '" + col6 + "', Returning_Date = '" + col7 + "', Departing_Time = '" + col8 + "', Returning_Time = '" + col9 + "';"

Is the correct formatting of that SQL statement.

sai.ayilavarapu commented: Thanks +0
Mike Askew 131 Veteran Poster Featured Poster

I think they mean how do you know whos not telling the truth, though I see no reason to do so as it isnt a competition xD

Rollercoaster tycoon 3

Daaaaaamn used to love that series, so need to get it again for pc :D

Mike Askew 131 Veteran Poster Featured Poster
using System.Text;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Cassandra myObject = new Cassandra();
            string a ="söt";
            a = myObject.hejsan(a);
            System.Console.WriteLine(a);
            Console.ReadLine();
        } 
    }
class Cassandra
        {
            public string hejsan(string value)
            {
                value +="Cassnadra";
                return value;
            }
        }
}

Line 10, you need to assign a to be the output of the method, as I have done in the above code.

Mike Askew 131 Veteran Poster Featured Poster

Nono, look at the first line of my code block, that is where the brackets go.

public string[] CreateCards()

Mike Askew 131 Veteran Poster Featured Poster
public string[] CreateCards( string[] Cards)
        {
            Cards = new string[52];
            for (int a = 0; a <= 51; a++)
            {
                if (a <= 12)
                {
                    Cards[a] = "   Hjärter " + (a+1).ToString();
                }
                if (a > 12 && a <= 25)
                {
                    Cards[a] = "   Ruter " + (a-12).ToString();
                }
                if (a > 25 && a <= 38)
                {
                    Cards[a] = "   Spader " + (a-25).ToString();
                }
                if (a > 38)
                {
                    Cards[a] = "   Klöver " + (a-38).ToString();
                }
            }
            return Cards;  //i get wrong here saying i need to return an array and Cards[] wont work
            //because they expect a value
        }

Need to add [] to the return in method declaration to make it an array.

Mike Askew 131 Veteran Poster Featured Poster

Right going back through the old questions, it shows the code is binding the data source of the grid to that lone data table, this is also the same in the unbind() method.

These will need to be updated to point to cashOrdersDS.Tables[0]

Mike Askew 131 Veteran Poster Featured Poster

Oh crud sorry I skim read your last post and completely missed what the code actually was!

cashOrdersDS(cashOrdersTable.Rows.RemoveAt(dataGridView2.SelectedRows[0].Index);

Replace with

cashOrdersDS.Tables[0].Rows.RemoveAt(dataGridView2.SelectedRows[0].Index);

Mike Askew 131 Veteran Poster Featured Poster

Correct that should be done :)

You may also want to check all your code for such occurances and alwasy reference the dataset, will keep all changes in one place then.

Mike Askew 131 Veteran Poster Featured Poster

cashOrdersTable will still remain a seperate entity in memory to the dataset, the dataset will simply create a copy of it in its own memory which you then refer to through the dataset.

Mike Askew 131 Veteran Poster Featured Poster

Haaaaannngggg On.

Whats cashOrdersTable? A lone datatable? Changes to this wont affect the tables in the dataset and so therefore your changes wont be pushed back to the database.

Similarly to another of your questions we need to be removing the rows from the table referenced in the dataset and not the lone datatable :) try that.

Mike Askew 131 Veteran Poster Featured Poster

I suggest you provide the error itself.

Also run a debug on the academic.aspx page and check what the session value contains when it loads.

Mike Askew 131 Veteran Poster Featured Poster

Well to get this exception you must be referring to the array location in some form (a loop or direct call) that goes past the length, therefore the index of what is causing the issue will be blatently obvious if you debug your code.

Array.Length returns an integer representing how many entries are in the array. The array however starts at 0 not 1 and so the length will always be one less than this as the length count starts at 1.

It is also worth noting 2d arrays and larger count each entry as in the array so a 2d array of size 10 will have a length of 20. Therefore a divide is needed on the length if you were to loop through it.

Mike Askew 131 Veteran Poster Featured Poster

This can be partially done using dtSelectedColumns.Select();

However this doesnt use actual SQL to do the selection simply a filter criteria.

For example dtSelectedColumns.Select("Age > 20"); would be the same as running Select * From dtSelectedColumns Where Age > 20. Of course this assumes you have an age column in the table and is purely an example.

So in yourcase it would probably be DataRow[] Results = dtSelectedColumns.Select("Column1Name = 'data'"); replacing Column1Name with the actual column name.

It is also worth looking into Linq querying for datasets, here.

Mike Askew 131 Veteran Poster Featured Poster

That was not a response to your request. I was answering the thread.

Mike Askew 131 Veteran Poster Featured Poster

Yeah you need to remove the cashDA.UpdateCommand = cb.GetUpdateCommand(); line, that wont work for you.

What happens if you use the line cashDA.Update(cashOrdersDS.Tables[0]);?

Mike Askew 131 Veteran Poster Featured Poster

Ummm going back to the original post. Can you check in the watch window whether the data set contains that table etc as we did in one of your other questions?

Just incase that ghost has come back to haunt us.

Mike Askew 131 Veteran Poster Featured Poster
private void btnOrderDelete_Click(object sender, EventArgs e)
        {
            System.Data.OleDb.OleDbCommandBuilder cb;
            cb = new System.Data.OleDb.OleDbCommandBuilder(cashDA);
            if (dataGridView2.SelectedRows.Count > 0)
            {
                cashOrdersTable.Rows.RemoveAt(dataGridView2.SelectedRows[0].Index);
                cashCustom.Open();
                cashDA.UpdateCommand = cb.GetUpdateCommand();
                cashDA.Update(cashOrdersDS.Tables["cashOrders"]);
                cashCustom.Close();
                MessageBox.Show("Record Deleted");
            }
            else
            {
                MessageBox.Show("Please Select a row");
            }
        }
    }

Try that.

Mike Askew 131 Veteran Poster Featured Poster

The code should look like this:

     private void btnOrderDelete_Click(object sender, EventArgs e)
        {
            System.Data.OleDb.OleDbCommandBuilder cb;
            cb = new System.Data.OleDb.OleDbCommandBuilder(cashDA);
            //connection declared here
            if (dataGridView2.SelectedRows.Count > 0)
            {
                cashOrdersTable.Rows.RemoveAt(dataGridView2.SelectedRows[0].Index);
                //connection opened here
                cashDA.Update(cashOrdersDS.Tables["cashOrders"]);
                //connection closed here
                MessageBox.Show("Record Deleted");
            }
            else
            {
                MessageBox.Show("Please Select a row");
            }
        }

That correct on your screen?

Mike Askew 131 Veteran Poster Featured Poster

I meant as in where you assign dRow, cashOrdersDS.Tables["cashOrders"].Rows[i][j]; use this to individually map each field to a textbox.

for example cashOrdersDS.Tables["cashOrders"].Rows[i][j] = Textbox1.Text; something along those lines

Mike Askew 131 Veteran Poster Featured Poster

Once again... You do not open a connection to the database before the line calling the dataadapter.Update() and then closing it after the line calling it.

It cant find a data table if it cant connect to the database now can it :)

This method call requires manual opening and closing of the connection unlike datadapter.Fill()

Mike Askew 131 Veteran Poster Featured Poster

Hmm sec let me dig back through some old code, swear there was a third line in that code block.

Updated:

I used to use:

.SuspendLayout();
.DataSource = null;
.DataSource = AB.Persons; //AB.Persons being a table in a dataset
.ResumeLayout();

However thats no different from what your running really apart from the layout suspension which means the unbind and rebind is not noticeable as the datagrid wont redraw until the resume is called.

OHHHHHHH I SEE IT.

Your making dRow equal to the row in the table. and then doing nothing with it, it is a seperate object to the table and so it wont update that row when you change properties of it. Change all the dRow calls to the row cell identities instead and it would work, else you can (i think) set the row to equal the dRow after filling it? One of those should work :)

Mike Askew 131 Veteran Poster Featured Poster

The dataadapter wont update the database without you opening a connection to it prior to the update call and closing it after.

If the datagrid isnt updating make a little method that unbinds its datasource, and then rebinds it again, then call that after you update the row. Thats how i've done it before anyway :)

Mike Askew 131 Veteran Poster Featured Poster
      <xsl:for-each select="nodename">
        <xsl:sort select="substring(., 5, 4)" data-type="number" order="ascending"/>
      </xsl:for-each>

That will work, we substring the node value to only look at the numerical part of it and then sort accordingly.

Mike Askew 131 Veteran Poster Featured Poster

You would need to use an XPath query to see if anything returns under the given name, then you can proceed from there with decision making logic

Mike Askew 131 Veteran Poster Featured Poster

Can you give a couple of examples of what your after to be allowed :) Can maybe invent a regex for it then.

Mike Askew 131 Veteran Poster Featured Poster

When adding a new article, change the discussion type to code snippet :)

Mike Askew 131 Veteran Poster Featured Poster

Hmm I'm not exactly sure to be honest at the moment.

Mike Askew 131 Veteran Poster Featured Poster

sorry for the delayed reply I was driving home from work for the last 2 n a bit hours.

Umm datasets dont take note of relationships unless you manually declare them within a dataset's tables using a relationship object and adding it.

It is more likely to be something to do with how the two lists query off each others values.

Mike Askew 131 Veteran Poster Featured Poster

Think there is a .Clear() on the DGV or something like that.

It is also worth noting your not using the datagrid tables again for the other database querying method :p forgot to mention earlier!

Mike Askew 131 Veteran Poster Featured Poster

I've been a noob.

The issue is that we are not assigning a table name and so therefore it wouldnt find the table with the old code.

You can assign the table in the dataset a name in the radiobutton code if you want using DataSet.Tables[0].TableName and then the code in the save can be reverted and should work :)

If I remember correctly, for future reference, you can also give tables names when instanciating them directly inside the dataset and so can probably do this on the line where you add the table to the dataset. Try adding a , after the table name and see if any of the overloads intellisense gives (assuming your using visual studio which im 99.9% sure you are) there might be one to assign a table name there.

Mike Askew 131 Veteran Poster Featured Poster

With regards to the connection open/close.

The DataSet.Fill() method automatically will open and close the connection with underlying code.

However if you do ever manually open the connection always remember to close it after the database related code has run. (you will need this once you want to update the database when we finally resolve this null dataset issue :D)

Do you always make the radiobutton code to populate the dataset run before trying to run the save method?

Mike Askew 131 Veteran Poster Featured Poster

I expect this was intending to be a code snippet and not a question?

Mike Askew 131 Veteran Poster Featured Poster

G'morning,

Ok while im reading the code, points to note for improvement:

  • Form1 Class

    • You can use one dataset to store multiple tables, thus eliminating the need for three to be declared, unless you have other reasons for doing this.
  • Form1_Load

    • You do not shut the connection after testing it to the database.
  • radioBtnCash_CheckedChanged

    • Your opening and closing the cashCustom connection and then running the SQL query for some reason (surprised this hasn't errored for you, run the SQL on an open connection to the DB, this could explain the empty dataset later on when its expected to be full?).

    • You add the cashCustomerTable to the dataset and then continue using it instead of your new table in the dataset to store data. Not much point adding it to the dataset if it wont be referred to, which it is then referred to in the save method where you'll be adding a row to a table with no data in (even when we did get the SQL to work).

  • btnSaveAcc_Click

    • Your referring to the cashCustomersTable and not the table in the dataset to create the row, you can do it from the dataset table also.

    • When adding a row to a table in the dataset, this will not push it through to the database and so the open connection is not required for that line. Instead you will then need to call a method afterwards from the dataadapter which is .Update(*DataSetNameForUpdate*, *"NameOfTableInDatasetToUpdate"*)

From the layout …

Mike Askew 131 Veteran Poster Featured Poster

Hmm it depends upon the execution order.

Im guessing the DataSet is filled at a specific action? In which case you could technically fill the DataSet on form load and store it as a form level variable so that it can be accessed by any method?

This would mean it would be filled when you go to use it as form level variables arent disposed of until the form is closed (or you tell it to dispose of itself).

Mike Askew 131 Veteran Poster Featured Poster

Yup confirms what I thought it would be.

The dataset is completely null at time of call.

It doesnt exist in the current context because there your looking for an exact object which obviously doesnt exist as the dataset it is within is null :)

Mike Askew 131 Veteran Poster Featured Poster

Can you screenshot the watch window at line 10 of the above code block.

In the watch window type cashCustomersDS.Tables.Count (will be a one line entry) and also cashCustomerDS.Tables[0].Rows.Count (again a one line response).