Mitja Bonca 557 Nearly a Posting Maven

Go and try my example code!!! It will not take more then 10 characters!!
Thats why we have key events.

Mitja Bonca 557 Nearly a Posting Maven

I would rather choose KeyPress event, where you can use "e" parameter and set its Handled property:

Private Sub textBox1_KeyPress(sender As Object, e As KeyPressEventArgs)
	If textBox1.Text.Length >= 10 Then
		If e.KeyChar <> ControlChars.Back Then
			e.Handled = True
		End If
	End If
End Sub
Mitja Bonca 557 Nearly a Posting Maven

Create column in a constructor of form (or on load event):

DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
{
    imageColumn.Name = "colImages";
    imageColumn.HeaderText = "Images";
    imageColumn.Width = 100;
    imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch;
    imageColumn.CellTemplate = new DataGridViewImageCell(false);
    imageColumn.DefaultCellStyle.NullValue = null;
}
datagridview1.Columns.Insert(imageColumn, 1); //1 is an index of column - 2nd column

then try using this kind of code:

Bitmap img = new Bitmap(@"C:\MyFolder\myPicture.jpg");
datagrdiview1[1, 0].Value = img; //0,0 is 1st row, 2nd column
//you can do a loop or something, its up to you

and you can add (subscribe to) an event, so it will show default images, if non inserted yet:

void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
     e.Row.Cells[1].Value = Properties.Resources.MyDefaultPicure. // add this image to Resources if you want to show it
}
Mitja Bonca 557 Nearly a Posting Maven

I see, you would like to show an error (exception) message if the value is not an integer, so you can use Parse method, and try, catch blocks:

int myInt;
try
{
     myInt = int.Parse(Console.ReadLine());
}
catch(Exception ex)
{
    Console.WriteLine(ex.Message);
}
Mitja Bonca 557 Nearly a Posting Maven

Like:

role r = new role();
if(int.TryParse(Console.ReadLine(), out r.Role_id))
{
     Console.WriteLine("Id inserted.");
}

In case if you dont want to show the message, you can do:

role r = new role();
int.TryParse(Console.ReadLine(), out r.Role_id);

but this way you would not know if value was inserted.

Mitja Bonca 557 Nearly a Posting Maven

Why you dont simply pass a reference of dataSet to Form2,and use it there as a dataSource of DGV2, the same as you did on form1 with DGV1?

But with one Exception: Make DataSet accessible for all Form1 class
Example:

//form1:
DataSet q2;

void PopulateDGV1()
{
   OdbcCommand bcCom2 = new OdbcCommand();
   bcCom2.CommandText = "" + content + "";
   bcCom2.Connection = OdbcCon;
   q2 = new DataSet();
   OdbcDataAdapter dbA2 = new OdbcDataAdapter(bcCom2);
   dbA2.Fill(q2);
   dataGridView1.DataSource = q2.Tables[0].DefaultView;
}

void OpenForm2()
{
    Form2 f2 = new Form2(q2);
    f2.Show();
}

//form2:
public Form2(DataSet _q2)
{
    dataGridView1.DataSource = _q2.Tables[0].DefaultView; //this is DGV on form2!!!
}
Mitja Bonca 557 Nearly a Posting Maven

This is very kinda a personal question. Every one has his own opinion on this, this question is like "Which car you like?". Im sure you will get almost as many different answeres, as many people you will ask.

But try to hold one princial: Keep same kind of data (methods in this case) together.
I would recommend you ones again to split methods into classes, so one class would have similar method and stuff around.
And try to hold on this 3 or n - Tier Arcitecture. This means splitting data into sectors:
- data access - if you work with databases),
- buisiness layer - additional code, like some calculations, ...
- graphical user interface (code for controls)

Mitja Bonca 557 Nearly a Posting Maven

Try to use this code:

using System;
using Microsoft.Win32;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            RegistryKey adobe = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe");
            if (adobe != null)
            {
                RegistryKey acroRead = adobe.OpenSubKey("Acrobat Reader");
                if (acroRead != null)
                {
                    string[] acroReadVersions = acroRead.GetSubKeyNames();
                    Console.WriteLine("The following version(s) of Acrobat Reader are installed: ");
                    foreach (string versionNumber in acroReadVersions)
                    {
                        Console.WriteLine(versionNumber);
                    }
                }
            }
        }
    }
}
Mitja Bonca 557 Nearly a Posting Maven

I didnt say you must not use Regions, sure you can, but they will only your code "less readable" is your code is "short".
Reagions comes right, I repeat, when you have a lot of code, maybe 1000 of lines on one *.cs file.

Otherwise, they are sure a good option to divide the code into peaces.
But remebember on thing too: its better to create more *.cs files then using Regions. The whole code still looks mor clear.

Mitja Bonca 557 Nearly a Posting Maven

Stop using region things, unless your code is really looong. Regions are only for your or someone elses notification to find some code faster, and its better organized as well.
Usually we put fields, properties, delegates on top of the class (together in some order), below are methods and events.

is there anything else you would like to know, something more specifically=

Mitja Bonca 557 Nearly a Posting Maven

using keyword is instead of calling Dispose() method.
The same is:

SqlConnection sqlConn = new SqlConnection"(connString");
// rest of code..
// on the end you close  or dispose IDisposable object:
sqlConn.Dispose();

//its EXACTLY thw same as:
using (SqlConnection sqlConn = new SqlConnection("connString"))
{
    // rest of code..
}

Calling Close() or dispose() methods is not the same. When you close an object, you can actually then open it again, while you Dispose it, this object get equl to null. So you cannot open it again, unless you instanitate it again (using new keyword).

Hope it helps.

Mitja Bonca 557 Nearly a Posting Maven

Try something like this:

string first = "someFirstName";
            string last = "someLastName";
            DateTime CurentDate = new DateTime(2011, 10, 5);
            DateTime SearchingDate = DateTime.MinValue;
            using (SqlConnection sqlConn = new SqlConnection("connString"))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "SELECT date FROM members WHERE name = firstname = @first AND lastname = @last";
                    cmd.Connection = sqlConn;
                    sqlConn.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                        if (reader.Read())
                            SearchingDate = (DateTime)reader[0];
                }
            }
            if (CurentDate.Date == SearchingDate.Date)
            {
                //both dates are equal!!
                //BUT DO NOT FORGET TO Compare DATES only - not full date, which includex hours, minutes, seconds, milliseconds)
            }
Mitja Bonca 557 Nearly a Posting Maven

Try converting data from database into soem number type, I will show you an example converting to decimal:

Dim total1 As Label = DirectCast(e.Item.FindControl("total1"), Label)
total1.Text = Convert.ToDecimal(e.Item.DataItem("receivable")) * 365 / Convert.ToDecimal(e.Item.DataItem("revenue"))

Remember, Math operations are only possible over math values (no strings involved).

Mitja Bonca 557 Nearly a Posting Maven

Your topic says about one row.
So i have answered on it.

If you want to copy more rows, you 1st have to know which rows exactly?!
Can you answer me on this question

From this code of yours it seems like you want to copy all the rows from DT to DGV.
Is this really what you want?

Mitja Bonca 557 Nearly a Posting Maven

LOL ...
My code works 100%, and it instets 1 row from dataTable to the last row of datagridview!!!
How you changed it? Do you know whta to change?
What is this code:

int rowIndex = dataGridView1.Rows.Add();

This code throws an error!!

Please paste my code into your code, all you have to do to use your own variable names.

Mitja Bonca 557 Nearly a Posting Maven
datagridview1.Rows.Add(); //add new row to dgv control
int rowIndex = datagridview1.Rows.Count - 1; //get this row`s index

//now insert one row from dataTable:
//I will show you how to add 1st row from dataTable:
int rowIndex = dataGridView1.Rows.Count - 1;
for (int i = 0; i < table.Rows.Count; i++) //loop through thr rows of dataTable
{
    if (i == 0) //only add row at index 0 (1st row in dataTable)
    {
        for (int j = 0; j < table.Columns.Count; j++) //loop through thr columns of dataTable
        {
             dataGridView1[j, rowIndex].Value = table.Rows[i][j];
        }
        break; //when done, code will leave for loop (of rows) - makes code faster!
    }
}

Hope this helps.

Mitja Bonca 557 Nearly a Posting Maven

What exactly is not working?
Does it work anything at all?

If you dont know exactly, set a break point just before this code, and go through it line by line, using F11 key.
This way you will exactly see whats really going on while looping through those two loops.

I double checked code i gave you, and it should work fine - if you are trying to find one person at a time.
PS: check if columns at index 3 are ok, if there isn`t any other index.

Mitja Bonca 557 Nearly a Posting Maven

:)
you too.
I know how it feels like when you want to do something very badly, and you cannot succeed it. Thats why I wanna give others as much as I know.
bye

Mitja Bonca 557 Nearly a Posting Maven

Hm, you didnt say last time when I did this code for you, you will be using a new member insertion.
If so, you have to do it a bit differently, you have to check if a user from the dataTable exists in DGV, and if not, then you can insert a new member.

Like:

bool bUserExistance = false;
            //foreach datagridRow in datagrid
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                // if not a new row
                if (!row.IsNewRow) //checking for a new row
                {
                    if (!bUserExistance)
                    {
                        string memberDGV = dataGridView1[3, row.Index].Value.ToString();
                        // foreach dataRow in dataTable
                        foreach (DataRow dr in table.Rows)
                        {
                            string memberDT = dr[3].ToString();
                            if (memberDGV == memberDT)
                            {
                                bUserExistance = true;
                                break;
                            }
                        }
                    }
                    else
                        break;
                }
            }

            if (!bUserExistance)
            {
                // MessageBox.Show("member is not in here");
                insertMember();
                insertDate();
            }
            else
            {
                // MessageBox.Show("Member is in dgc");
                insertDate();
            }

SO this code now will go through all the rows of DGV and on each row will check all the rows of DataTable. If the use will be found, it will leave the both loops. If user will not be found will (for sure loop both the loops to the end), and when (in both cases) when leave the Rows of DGV loop, it will execute the code, regarding on the boolean flag.

Hope this will salve your problem.

Mitja Bonca 557 Nearly a Posting Maven

Sure you can. Simply create new DGVcomboBox column and add or insert it to dgv columns.

DataGridViewComboBoxColumn cmbcolumn = new DataGridViewComboBoxColumn(); 
{
    cmbcolumn.Name = "cmbColumn";
    cmbcolumn.HeaderText = "combobox column"; 
    cmbcolumn.Items.AddRange(new string[] { "aa", "ac", "aacc" }); //items in comboBox
}
dataGridView1.Columns.Insert(1, cmbcolumn); //inserting comboBox into 2nd columns (colimn at index 1)
Mitja Bonca 557 Nearly a Posting Maven

There must be a space. Space must be between every single word in a query, otherwise they are meant as one.

Mitja Bonca 557 Nearly a Posting Maven

You can do it this way:

Private Sub button1_Click(sender As Object, e As EventArgs)
	Dim couter As Integer = 1
	For i As Integer = 0 To dataGridView1.Rows.Count - 1
		If Not dataGridView1.Rows(i).IsNewRow Then
			dataGridView1("rollNo", i).Value = [String].Format("{0}-{1}", "11", System.Math.Max(System.Threading.Interlocked.Increment(couter),couter - 1).ToString().PadLeft(4, "0"C))
		End If
	Next
End Sub

The code addes values form "11-0001" to the last student in the dgv. Enumeration is by 1 up.

Mitja Bonca 557 Nearly a Posting Maven

Hi, please check here how to use Like condition. Its all well explained.
bye

Mitja Bonca 557 Nearly a Posting Maven

The same error: Incorrect syntax near '.'??
Please double check the correctness of table names and fields.

Mitja Bonca 557 Nearly a Posting Maven

Hmm, and where is a Timer reference? Times instantiation code?
And why are 3 if blocks (same one) needed? You only create one.
Take a look.

Full code should look like:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//for this code bellow you dont need  Threading namespace!!!

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        //Timer is from Windows.Froms namespace!
        Timer timer1;
        Login login;
        public Form1()
        {
            InitializeComponent();
            //timer instantiation:
            timer1 = new Timer();
            timer1.Interval = 1000; //every second will be called an event Tick
            timer1.Tick += new EventHandler(timer1_Tick);             
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //start timer:
            timer1.Start();    
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            progressBar1.Increment(1);
            if (progressBar1.Value == 100)
            {
                timer1.Stop();
                progressBar1.Hide();
                this.Hide();
                login = new Login();
                login.Show();
                //I Add This As Notes in Order to Debug Without Errors
            }
        }
    }

    //login form:
     public partial class Form1 : Form
     {
          public Login()
          {
               InitializeComponent();
               MessageBox.Show("It Works, and welcome on login form!", "Welcome note.)", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
          }
     }
}
Mitja Bonca 557 Nearly a Posting Maven

You have to know that dataTable by default has object type. No string ot integer.
So if you want to pass some integer value, you have to explicitly (or implicitly) convert it.

Mitja Bonca 557 Nearly a Posting Maven

nice :)

foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        string memberDT = dr[0].ToString(); //0 is the index for the 1st column, so you have to adapt the code to suit the column indexes
                        if (memeberDGV == memberDT)
                        {
                            //member already exists in dgv!
                            count++;
                        }
                    }

the same goes for the columns in the dgv. Just set the indexes or columns names, so it will check the same ones.

Mitja Bonca 557 Nearly a Posting Maven

Remember, messages boxes, like you had them inside the code, will fire each row when looping through the dataTable. This is ok and normal (I reapeat, like you had them inside the loop).
I suggest you to use my code from the previos post, to notifly the user about duplications (if nothing else).

Mitja Bonca 557 Nearly a Posting Maven

I would suggest you to do show the message only ONES - after the checking is all done.
So do it like:

int count = 0;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (!row.IsNewRow) //checking for a new row
                {
                    string memeberDGV = dataGridView1[0, row.Index].Value.ToString();
                    foreach (DataRow dr in table.Rows)
                    {
                        string memberDT = dr[0].ToString();
                        if (memeberDGV == memberDT)
                        {
                            //member already exists in dgv!
                            count++;
                        }
                    }
                }
            }
            if (count > 0)
                MessageBox.Show(String.Format("{0} {1} already in the list. {2} not coppied.", count, (count == 1 ? "member" : "members"), count == 1 ? "It was" : "They were"));
Mitja Bonca 557 Nearly a Posting Maven

Sure you are keep on getting messages. For every single check of the user, no matter if its in the "list" of dgv, or not.

Do you want to show the meesage only for the user which is already in the list, or you would like to show the message only ones - on the end, which will tell "There is/are usres in the list??

Mitja Bonca 557 Nearly a Posting Maven

Show me your whole code of this.

Mitja Bonca 557 Nearly a Posting Maven

I would say this is happening in the last row, where no data in presented.
Try to do some checking for a "NewRow", this is the property which checks if the row is a new one (the last one actually):

DataTable table = new DataTable(); // get the members (new ones)
            //now lets check if the member from table is already in the DGV:
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (!row.IsNewRow) //checking for a new row
                {
                    string memeberDGV = dataGridView1[0, row.Index].Value.ToString();
                    foreach (DataRow dr in table.Rows)
                    {
                        string memberDT = dr[0].ToString();
                        if (memeberDGV == memberDT)
                        {
                            //member already exists in dgv!
                        }
                    }
                }
            }
Mitja Bonca 557 Nearly a Posting Maven

Just make sure the able name of the DataTable objects (the variable name, like I used "table") are different. With other words, table names must be different one to each other. Then you can have 100 of them at ones.

Mitja Bonca 557 Nearly a Posting Maven

If its only this, then yoz can do:

// firstname, lastname, membership, accountid, date
            DataTable table = new DataTable(); // get the members (new ones)
            //now lets check if the member from table is already in the DGV:
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                string memeberDGV = dataGridView1[0, row.Index].Value.ToString();
                foreach (DataRow dr in table.Rows)
                {
                    string memberDT = dr[0].ToString();
                    if (memeberDGV == memberDT)
                    {
                        //member already exists in dgv!
                    }
                }
            }
Mitja Bonca 557 Nearly a Posting Maven

For the password, you should use ExecuteDataReader()

ExecuteSclalar is appropriate here too, because it returns a single value.
But its not appropriate to return the password, because you dont actually use it any where, password should only (meant) be to check if the user is the right one, or not.
But I dont exactly know why you use the password, so do as you like.

Mitja Bonca 557 Nearly a Posting Maven

This is a not a problem code.
I actually really dont understand what exactly are you trying to do here.
Ok, you this SELECT sql query, which gets Users data (fist and last name, and id).
You populated DGV with these data.
Then what?

Please dont just from one issue to another.
Continue from where I stopped.

Mitja Bonca 557 Nearly a Posting Maven

1. You have a WPF project and It already has a window. You are able to run this application.

2. Now you right click on the project and Add new Window. You name it MyNewWindow.xaml

3. You would now notice MyNewWindow.xaml and MyNewWindow.xaml.cs added to your project. (the class name for the window would be MyNewWindow which is in the .xaml.cs file and it derives from Window; also a partial class)

4. Open the XAML file for the MyNewWindow (MyNewWindow.xaml) and add your controls. Treat it like any other window and write code.

5. Now in your main window (the first one) you add a Button which when clicked should show the newly created window.

For that inside the Click handler, ....

var newWindow = new MyNewWindow();
newWindow.Show();


This would create a new instance of the MyNewWindow and shows it to the user. It would appear just as you designed in your XAML.

If this is an issue, let me know so that I will upload a sample application and link you with it.

Mitja Bonca 557 Nearly a Posting Maven

What I meant is (in my upper question) do you use any textBox or any other control to find the member?
I dont know how you are looking for, what is your criteria.
I need more data...

abd btw, you said you have data in database. This application is actually for searching and updating user`s data, am I right?

Mitja Bonca 557 Nearly a Posting Maven

Hi,
What do you mean? How you intend to find it?

Mitja Bonca 557 Nearly a Posting Maven

If you got the answer, please close the thread by marking as salved (answered).
thx in advance ;)

Mitja Bonca 557 Nearly a Posting Maven

hehe, no problem mate, I really like to help.
Cya around.

Mitja Bonca 557 Nearly a Posting Maven

You have to use UPDATE sql statement, not INSERT!!
like:
"UPDATE MyTableName SET @field2, @field3, @filed4 WHERE FieldName1 = @filed1"

Behind the SET keyword specify the field names (columns) you want to update. No need all, just those you want to update. And you must use a WHERE clause, so the code knows which row to update.
As simple as that.

Mitja Bonca 557 Nearly a Posting Maven

Hmm, then we have a problem here.
The code is meant to work in Win form.
About the generic list, it uses a "System.Collections.Generic" namespace (reference).

Put this code into a win form, and dont just copy/paste it, but you have to add event for controls, like (buttonSource_Click, ...), and then paste the code from here to your event.

ddanbe commented: Helpfull! +14
Mitja Bonca 557 Nearly a Posting Maven

LOL - your form look EXACTLY the same as mine :) , but I mean EXACTLY the same. Even buttons have three dots inside. Unbelivable.

So I can give you the code:

List<FileInfo> listOfFiles;
        public Form1()
        {
            InitializeComponent();
            listBox1.SelectionMode = SelectionMode.MultiSimple;
        }

        private void buttonSource_Click(object sender, EventArgs e)
        {
            listOfFiles = new List<FileInfo>();
            FolderBrowserDialog openFileDialog1 = new FolderBrowserDialog();
            openFileDialog1.SelectedPath = @"C:\";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string dirPath = openFileDialog1.SelectedPath;
                //set the path to the textBOx:
                textBox1.Text = dirPath;
                //filter for all images:
                string[] filters = { "*.jpg", "*.bmp", "*.png" };

                //get all the imeges to a list<T>:
                foreach (string filter in filters)
                {
                    FileInfo[] files = new DirectoryInfo(dirPath).GetFiles(filter);
                    foreach (FileInfo file in files)
                    {
                        listOfFiles.Add(file);
                    }
                }
            }
            //adding file names to listBox:
            foreach (FileInfo file in listOfFiles)
                listBox1.Items.Add(Path.GetFileNameWithoutExtension(file.FullName));
        }

        private void buttonDestination_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog openFileDialog1 = new FolderBrowserDialog();
            openFileDialog1.SelectedPath = @"C:\";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string dirPath = openFileDialog1.SelectedPath;
                //set the path to the textBOx:
                textBox2.Text = dirPath;               
            }
        }

        private void buttonProcess_Click(object sender, EventArgs e)
        {
            //I will only show how to work with selected files from listBox:
            //my example will only count selected files:
            int counter = 0;

            for (int i = 0; i < listBox1.SelectedItems.Count; i++)
            {
                string name = listBox1.SelectedItems[i].ToString();
                //find the file in generic list:
                foreach (FileInfo file in listOfFiles)
                {
                    if (name == Path.GetFileNameWithoutExtension(file.Name))
                    {
                        counter++;
                        //you use the destinaton path here to do something (or you will copy or what ever)!!
                    }
                }
            }

            MessageBox.Show("You …
Mitja Bonca 557 Nearly a Posting Maven

Hi, Im doing some code for you.
I have salved the 1st point (I am using "FolderBrowserDialog" object - which is only meant to choose a folder, so no files showed; thisis best for you since you want to get only spcific files.

Lets go to 2. point:
Why would you have then two textBoxes. Didnt you say in 1st point that you have a button to choose the directory? Why then having a directory path in the source textBox? The source path you will choose with that button.
We can do this way:
- two textBoxes
- two buttons on the end of those textBoxes
- on clicking on each button, FolderBrowserDialog will open and you will choose the destinations (for source and for destination path).


4. point is simple you will work only with "SelectedItems".

What do you think?

Mitja Bonca 557 Nearly a Posting Maven

I guess soem of your converting to integer from stirng throuwn an exception.
Please double check if your textBoxes which MUST have integers only, do really have them. My guess is that is one of them textboxes there is not only a number inside (a number without any decimal places -thats an integer).

What you can do, to make sure this kind of exception will not happen again, is to use some int checking (I will only show you two examples, for the rest do it by your own):

string payNoSp = PayNoSp.Text;
string addsp = Addsp.Text;
if(int.TryParse(payNoSp, out paynosp) && int.TryParse(addsp, out spAdd))
{
     if (stype == "Baptismal")
     {
         stypeid += "1";
         payfp += "200";
     }
     //and rest of the code here bellow...
}
else
     MessageBox.Show("Please insert only numbers for appropaite fields.");
Mitja Bonca 557 Nearly a Posting Maven

try this:

Dim exampe As String = "this is text."
Dim bigLetter As String = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(exampe)
Mitja Bonca 557 Nearly a Posting Maven

Then you can try to do:

Console.Write("Enter command =>");
String command = Console.ReadLine();
int i = 0;
if (command.Length ==1) 
    Int32.TryParse(command.Substring(0,1), out i); //1 character input
else if(command.Lenght == 2)
    Int32.TryParse(command.Substring(1,1), out i); //2 characters input
//or more if you need

In case if you only want to get last character (if there is only character, it will take 1), then you can do:

Console.Write("Enter command =>");
string command = Console.ReadLine();
int i = int.Parse(command.Substring(command.Lenght -1, 1)); //this will always return last character - and oyu make sure its an integer!!
Mitja Bonca 557 Nearly a Posting Maven

Substring is a method that has two parametes:
1. Starting index
2. Numbers of characters

So when you call Substring(1, 1) -> that means you are taking 2nd character only (starting index is 1, and you take 1 character).

And because you are parsing to integer - it MUST be an integer. If there anythng else then a number it will give an error.

So a better handling of this kind of an exception, would be to check which character this is, and then decide what to do, like:

Console.Write("Enter command =>");
string command = Console.ReadLine();              
int i = 0;
if(int.TryParse(command.Substring(1, 1), out i)) //do the checking is characte is really a number 
{                
     if(command == "m") menu(); 
     else if (command == "p") PrintPuzzle(); 
     else if (command.Substring(0, 1) == "n") shuffle(i);
     else if (command.Substring(0, 1) == "r" && i<= numCols) moveRowRight(i);
     else if (command.Substring(0, 1) == "c" && i <= numRows) moveColDown(i);
     else if (command.Substring(0, 1) == "x")
           System.Environment.Exit(0);
     else     
           Console.WriteLine("Invalid command entered.");
}
else
       Console.WriteLine("Character is not a number - cannot continue.");
Mitja Bonca 557 Nearly a Posting Maven

Change sql query to:

insertDatetime = @"UPDATE WaynokaLogger SET Date = @Date WHERE AccountID = '" + newString + "'";

or use parametreized query:

insertDatetime = "UPDATE WaynokaLogger SET Date = @Date WHERE AccountID = @id";
da.UpdateCommand = new SqlCommand(insertDatetime, cs);
da.UpdateCommand.Parameters.AddWithValue("@Date", SqlDbType.DateTime).Value = DateTime.Now;
da.UpdateCommand.Parameters.AddWithValue("@id", SqlDbType.Int).Value = newString;