Mitja Bonca 557 Nearly a Posting Maven

Use have to to sqlExecuteNonQuery() method to exectute an insertion.

sq1 = "insert into [" + Box1.Text + "] values('" + accid.Text + "', '" + pass.Text + "', '" + sex.Text + "', '" + email.Text + "')"; 
cmd = new SqlCommand(sq1, cn);
cmd.ExecuteNonQuery(); //HERE!
Mitja Bonca 557 Nearly a Posting Maven
if (DialogResult.Yes == MessageBox.Show("Do you want to save into a database?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {

                //SAVE into database
            }
            else
            { 
            //not saving! then you dont even need this else (you can erase it if you dont need it
            }
Mitja Bonca 557 Nearly a Posting Maven

Lol, this post isnt good either.
Find out way by your self.


a tip: i have an issue with this code:

data = table.Rows[i]["Name"];
if(data < 10 ? _value1 + 2 : _value2 - 2;

If you find out what would be probem here, then I will find whats the matter in your code.

Mitja Bonca 557 Nearly a Posting Maven

YOu forgot to include ' ' to the query around property textbox.Text). Your create query has to look like:

sq1 = "CREATE TABLE '" + TextBox1.Text + "'(myId INTEGER CONSTRAINT PKeyMyId PRIMARY KEY," +"myName CHAR(50), myAddress CHAR(255), myBalance FLOAT)";
Mitja Bonca 557 Nearly a Posting Maven

hmmm...
Comset2 is what? Where do you inizialize it? What kind of collection is it?

Mitja Bonca 557 Nearly a Posting Maven
string str = "1 2 : 3";
str = str.Replace(":","");
string[] array = str.Split(' ');
string third = array[2];
string secnond = array[1];


//to get only 3 out of the whole string
stirng three = str.Substring(str.Lenght -1, 1);
Mitja Bonca 557 Nearly a Posting Maven

Simple:
Constructor is only a method, which has this previlege that is called first when a new instance of a class (or form) is created. It is called automatically when this instance gets created.

Mitja Bonca 557 Nearly a Posting Maven

Please mark this thread as answered, because it was ANSWERED already (at least regarding the thread`s title).
And get serious (and books too).
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Would you please stop with the threads names as "Help,,!!". This is getting us no where. And please, stop posting double or even more same posts. All aobut these numbers.
Create one thread and hold to it!! I have answered on a couple of your threads, but NONE has been answered so far. So, I wont even help you out any longer, and I doubt any one will.

Please, get serious, get some books and study! Dont bother us here with every single homework, that you teacher gives it to you.
Sorry for sounding so harsh, but this is pis... me off slowely. This is just not the way to receive help, and a knowledge.

Mitja

ddanbe commented: Right! +9
Mitja Bonca 557 Nearly a Posting Maven

This how:

string a = "1 2 : 3";
            string b = a.Replace(":", "");  //removes :
            string[] split = b.Split(' ');   //splits to 3 characters

Mitja

Mitja Bonca 557 Nearly a Posting Maven

lol - what a help :)
check your pm.

Mitja Bonca 557 Nearly a Posting Maven

Check out this code:

public partial class Form1 : Form
    {
        Dictionary<string, double> dic = new Dictionary<string, double>();
        public Form1()
        {
            InitializeComponent();
            listBox1.Items.AddRange(new string[] { "{1 2} 4", "{1 4} 6", "{1 5} 7", "{1 3 4} 8" });
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string line = listBox1.SelectedItem.ToString();
            string _key = Regex.Match(line, @"{(.*?)}").Groups[1].Value;
            string _value = line.Remove(0, ((line.IndexOf("}") + 2)));
            double dValue = 0;
            if (double.TryParse(_value, out dValue))
            {
                if (dic.ContainsKey(_key))
                    dic[_key] = dValue;
                else
                    dic.Add(_key, dValue);

                //I will even remvoe the selected item from the listBox (so you donw have duplicates).
                //If you dont want to remove, simply dont use this code.
                listBox1.Items.Remove(line);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //check what have you stored into the dictionary:
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("These is what you have stored into the dictionary<string, double> :");
            foreach (KeyValuePair<string, double> kvp in dic)
            {
                sb.AppendLine(String.Format("Key: {0}, Value: {1}", kvp.Key, kvp.Value));
            }
            MessageBox.Show(sb.ToString());
        }
    }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

The listbox content is as below:
{1 2} 4
{1 4} 6
{1 5} 7
{1 3 4} 8

1st column is what is in the brackets? And the value out of brackets is your 2nd column, which would be the Value of the dictionary?

Mitja Bonca 557 Nearly a Posting Maven

Here is the colution:

private void dataGridView1_CellClick(object obj, DataGridViewCellEventArgs e)
        {
             int rowindex = e.RowIndex;
            List<object> data = new List<object>();
            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                if (rowindex == row.Index)
                {
                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        //SET INDEXES OF THOSE 2 COLUMNS WHERE YOU HAVE ID AND NAME
                        //my example code shows 1st and 2nd column (indexes of 0 and 1):
                        if (e.ColumnIndex == 0 && e.ColumnIndex == 1) 
                            data.Add(cell.Value.ToString());
                    }
                    break;
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

So get only data from those 2 columns where is ID and a Name.

Mitja Bonca 557 Nearly a Posting Maven

simply hide the form2 (which will show from1). And when you need to show form2 again, just call form2.Show() method. thats it.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

No problem. Just mark the thread as answered (or vote as helpful) - to close the thread,
bye
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Does the list get filled up?

I asked you how many columns does your DGV have?
my code was made for 2 columns, so if you dont have two (less or more) might be a problem.
You have to get two values into a List<object>, those from two columns (id and name).

Mitja Bonca 557 Nearly a Posting Maven

You ca ndo it this way:

//form1:
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form3 f3 = new Form3();
            Form2 f2 = new Form2(f3);
            f2.Show();
        }
    }   

//form2:
 public partial class Form2 : Form
    {
        Form3 f3;
        public Form2(Form3 _f3)
        {           
            InitializeComponent();
            f3 = _f3;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            f3 = new Form3();
            f3.Show();
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Ok this should do it. And I understand what the teacher can suspect that this is not your code. :)

class Program
    {
        static void Main(string[] args)
        {
            Student st1 = new Student();
            Student st2 = new Student();

            Console.WriteLine("give the elements of the firts student:");
            Console.WriteLine("Name:");
            st1.Name = Console.ReadLine();
            Console.Write("AM:T0");
            st1.AM1 = Int32.Parse(Console.ReadLine());
            Console.WriteLine("first grade:");
            st1.Grade1 = Double.Parse(Console.ReadLine());
            Console.WriteLine("second grade:");
            st1.Grade2 = Double.Parse(Console.ReadLine());
            Console.WriteLine("third grade:");
            st1.Grade3 = Double.Parse(Console.ReadLine());

            Console.WriteLine("give the elements of the second student:");
            Console.WriteLine("name:");
            st2.Name = Console.ReadLine();
            Console.Write("AM:T0");
            st2.AM1 = Int32.Parse(Console.ReadLine());
            Console.WriteLine("first grade:");
            st2.Grade1 = Double.Parse(Console.ReadLine());
            Console.WriteLine("second grade:");
            st2.Grade2 = Double.Parse(Console.ReadLine());
            Console.WriteLine(" third grade:");
            st2.Grade3 = Double.Parse(Console.ReadLine());

            double AV1, AV2, sum;

            AV1 = (st1.Grade1 + st1.Grade2 + st1.Grade3) / 3;
            AV2 = (st2.Grade1 + st2.Grade2 + st2.Grade3) / 3;
            sum = (AV1 + AV2) / 2;

            Console.WriteLine("------------------");
            Console.WriteLine("The 1.st student {0} has an average of {1}.", st1.Name, Math.Round(AV1, 2));
            Console.WriteLine("The 2.nd student {0} has an average of {1}.", st2.Name, Math.Round(AV2, 2));
            Console.WriteLine("The both together have the average of {0}", Math.Round(sum, 2));
            Console.ReadLine();
        }
    }

    class Student
    {
        private string _Name;
        private int AM;
        private double grade1;
        private double grade2;
        private double grade3;

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        public int AM1
        {
            get { return AM; }
            set { AM = value; }
        }

        public double Grade1
        {
            get { return grade1; }
            set { grade1 = value; }
        }

        public double Grade2
        {
            get { return grade2; }
            set { grade2 = value; }
        }

        public …
Mitja Bonca 557 Nearly a Posting Maven

And this is the method you have it on Form1:

etDataFromDoctorGridView

right?

So where is the problem? I dont see it, at least if you populate the dataGridView.

How many columns do you have in the dgv? Please, put a break point on dgv_CellClick event, to see whats going on.

Mitja Bonca 557 Nearly a Posting Maven

Show me your code of Form2...

Mitja Bonca 557 Nearly a Posting Maven

Check this out:

class Program
    {
        static void Main(string[] args)
        {
            Grade st1 = new Grade();
            List<Grade> gradesList = new List<Grade>();

            Console.WriteLine("Give the elements of the firts student:");

            Console.Write("Name: ");
            st1.Name = Console.ReadLine();

            Console.Write("AM:T0 ");
            st1.AM = Int32.Parse(Console.ReadLine());

            for (int i = 1; i <= 3; i++)
            {
                Console.Write(i + GetEnumerations(i) + " grade: ");
                Grade g = new Grade();
                g.Grades = double.Parse(Console.ReadLine());
                gradesList.Add(g);
            }

            //calculate and write out all the grades:
            Console.WriteLine("-----------------");
            Console.WriteLine("For the grades of {0}:", st1.Name);
            foreach (Grade g in gradesList)
                Console.WriteLine(g.Grades);
            Console.WriteLine("The average degree is: {0}.", Math.Round(gradesList.Sum(a => a.Grades) / gradesList.Count, 2));
            Console.ReadLine();
        }

        private static string GetEnumerations(int value)
        {
            string InWord = null;
            switch (value)
            { 
                case 1:
                    InWord = "st";
                    break;
                case 2:
                    InWord = "nd";
                    break;
                case 3:
                    InWord = "rd";
                    break;
                default:
                    InWord = "th";
                    break;
            }
            return InWord;
        }
    }

    class Student
    {
        public string Name { get; set; }
        public int AM { private get; set; }
    }

    class Grade : Student
    {
        public double Grades { get; set; }
    }

What do you think?
But thr properties are not private, otherwise you cannot access to them (you can write them, but not read - which Iam doing on the end of the code, where Iam writing outputs.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

So? we are willing to teach you how to do it correctly. Any progress?

Mitja Bonca 557 Nearly a Posting Maven

@Mitja
What is wrong with StringBuilder and append?

LOL, you dont get it, me and Momerath had some issues in the past, I was constantly using apending string to string. And he then tought me to use StringBuilder instead.
Thx for that Momerath.
Appreciate it.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

so you mean i have to use a constructor?

Constructor is nothing more then an ussual method, which has this privilegue, that it called as the 1st method after class initialization! So the answer is No!

Mitja Bonca 557 Nearly a Posting Maven

another thing regarding those 5-9 lines:
Create properties with get,set accessors!
And you can set get as private:

public string name {private get; set; }
Mitja Bonca 557 Nearly a Posting Maven

maybe a bit off topic..

Momerath: ... StringBuilder!!! :)
dont use any array, or "appanding" a text to a text, like myString +=something!

:)
I have learned that now.

Mitja Bonca 557 Nearly a Posting Maven

Where do you initialite a new instance of a class Student? NoWhere.
For to do it so, you have to create a local variable of a class:

Student st1 = new Student(); //s1 is now a reference of a class.

for beginining...

Mitja Bonca 557 Nearly a Posting Maven

yes, Reader is used to get more values (specific ones).

Mitja Bonca 557 Nearly a Posting Maven

Mate, if this is not you final version of the project, I wont even help you out.
That it wont be like last time, when I did the code for you (school homework I guess), and then you came out later to ungrade it.
No, cant do.

So, what is it gonna be?
Is this it, or not?

Mitja Bonca 557 Nearly a Posting Maven

Do:

public partial class coffeeOrders : Form
    {
        public coffeeOrders()
        {
            InitializeComponent();
        }
 
        DataSet orderDataSet = new DataSet();
        private void coffeeOrders_Load(object sender, EventArgs e)
        {
 
            string connection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=H:\UCP\C And ASPNET\Coffee.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
            DataTable table = new DataTable("Orders");
            //add  table to dataSet:
            orderDataSet.Tables.Add(table);

            SqlConnection cn = new SqlConnection(connection);             
            string strSQL = "SELECT * FROM CustomerOrders";
            SqlCommand cmd = new SqlCommand(strSQL, cn);
            SqlDataAdapter myDataAdapter = new SqlDataAdapter(cmd);
            myDataAdapter.Fill(table);
        }
        private void btnDisplayAll_Click(object sender, EventArgs e)
        { 
            foreach (DataRow dRow in orderDataSet.Tables["Orders"].Rows)
            {
                //CHECK FOR THE CORRECT NAMES OF THE COLUMNS IN DAATABLE CALLED: ("table")!!!!
                
                ListViewItem lstItem = new ListViewItem(dRow["OrderID"].ToString());
                lstItem.SubItems.Add(dRow["CoffeeName"].ToString());
                lstItem.SubItems.Add(dRow["CoffeeGrind"].ToString());
                lstItem.SubItems.Add(dRow["Price"].ToString());
                lstItem.SubItems.Add(dRow["Quantity"].ToString());
                //lstItem.SubItems.Add(dRow["QuantityInStock"].ToString());
                //lstItem.SubItems.Add(dRow["Pic"].ToString());
                listView1.Items.Add(lstItem);                
            } 
        }
 
 
       //private void listView1_SelectedIndexChanged(object sender, EventArgs e)
       //{
 
       //}
    }

And please dont use that try, catch blocks in there - no needed at all (just make sure that connString is valid!!
And always will be OK!! Understood?

Hope this helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Code works fine. I have tested it (becuase I made it by my self).

btw, could you just copy-past the code to your clean project? The only think that C# generates its self is th button click (to open form2).
This one you have to put it on the form and add an event of the Click (and paste the code from my button_click to yours). All other code you just copy-paste.

It has to work.
And btw, where did you find this like of code in mine:

f1.GetDataFromDoctorGridView(data);

My code only has:

f1.GetDataFromForm2(data);
Mitja Bonca 557 Nearly a Posting Maven

Check out this code:

//form1:
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(this);
            f2.Show();
        }

        public void GetDataFromForm2(List<object> list)
        {
            textBox1.Text = list[0].ToString();
            textBox2.Text = list[1].ToString();
        }
    }

//form2:
public partial class Form2 : Form
    {
        Form1 f1;
        List<Doctor> list;
        public Form2(Form1 _f1)
        {
            InitializeComponent();          
            this.dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
            this.f1 = _f1;

            //populate DGV:
            PopulateDoctors();
        }

        private void PopulateDoctors()
        {
            list = new List<Doctor>
            {
                new Doctor{ID=1, Name="Doctor 1"},
                new Doctor{ID=2, Name="Doctor 2"}
            };
            dataGridView1.DataSource = list;
        }

        private void dataGridView1_CellClick(object obj, DataGridViewCellEventArgs e)
        {
            int rowindex = e.RowIndex;
            List<object> data = new List<object>();
            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                if (rowindex == row.Index)
                {                   
                    foreach (DataGridViewCell cell in row.Cells)
                        data.Add(cell.Value.ToString());
                    break;
                }
            }
            //send data to form1:
            f1.GetDataFromForm2(data);
            //close this form2:
            this.Dispose();
        }
    }

    class Doctor
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

To fill the dataTable you have to do:

string connection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\UCP\C And ASPNET\Coffee.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
            DataTable table = new DataTable("MyTable");
            SqlConnection cn = new SqlConnection(connection);
            //no need of try catch, just make sure the connString is ok!
            cn.Open();
            string strSQL = "SELECT * FROM CoffeeTypes";
            SqlCommand cmd = new SqlCommand(strSQL, cn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(table);

This will work 100%

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Did you set the View property of gridView?

listView.View = View.Details;

hope it something like it (Iam telling you by heart)
Mitja

Mitja Bonca 557 Nearly a Posting Maven
Mitja Bonca 557 Nearly a Posting Maven

Depents what type are these different versions. If they are both numbers you can use:
==, >=, <=, >, < (all of them).
If they are a string you cannot use any. Becuase it will simply not work. YOu cannot compare the difference in the string, you can only compare if they are same (or different) lenght, or they are equal (or not); meaning if they are really equal (like: "aaa" == "aaa" > true, "aaa" != "aaa" > false, "aaa" == "aab" > false

You see the difference?
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Try this code:

int total = 0;
            foreach (DataGridViewRow row1 in dgv1.Rows)
            {
                foreach (DataGridViewRow row2 in dgv2.Rows)
                {
                    if (row1.Index == row2.Index)
                    {
                        total += (int)row1.Cells[0].Value * (int)row2.Cells[0].Value;
                        break;
                    }
                }
            }
            //when code leaves these two loops (so comes here), the "total" local variable holds the result

Mitja

Mitja Bonca 557 Nearly a Posting Maven

You have an error on row No.20. It should be like this:

dateTimePicker1.Value = Convert.ToDatetime(drr["BILL DATED"]);
ddanbe commented: Nice. +9
Mitja Bonca 557 Nearly a Posting Maven

It has to written like this:

cmd.CommandText = "select employee_code from MST_Employee where employee_code = '" + emp_code + "';

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Impossibe in these kind of collections.
You cannot store type string into type of variable.
What do I mean: your 1st array has the string as for a key, and 2nd array`s Value is the double.
Chanage that. Then you simply code the key from array1 to the value of array2.

Do a loop of KeyValuePair<sting, double> of the dictionary1, and pass the key of the current to the value of the 2nd dictionary.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Check this out:

PLEASE: take time and study the example. Code works, you only have to adapt to your needs.

public partial class Form1 : Form
    {
        bool bSkipping;
        DataTable table;
        public Form1()
        {
            InitializeComponent();         
            string[] semesters = { "1st", "2nd", "3rd" };
            comboBox1.DataSource = semesters;
            comboBox1.DisplayMember = "Value";
            comboBox1.SelectedIndex = -1;

            comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
            comboBox2.SelectedIndexChanged += new EventHandler(comboBox2_SelectedIndexChanged);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //RESET dataTable
            if (table != null)
            {
                table.Clear();
                table = null;
            }

            string[] programme = null;
            bSkipping = true;
            switch (comboBox1.SelectedItem.ToString())
            {
                case "1st":
                    programme = new string[] { "Programme A", "Programme B", "Programme C" };
                    break;
                case "2nd":
                    programme = new string[] { "Programme D", "Programme E", "Programme F" };
                    break;
                case "3rd":
                    programme = new string[] { "Programme G", "Programme H", "Programme I" };
                    break;
                default:
                    break;
            }
            comboBox2.DataSource = programme;
            comboBox2.DisplayMember = "value";
            comboBox2.SelectedIndex = -1;
            bSkipping = false;
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!bSkipping)
            {
                //I have only my own code to populate DGV: you have to get yours:
                PopulateDGV(comboBox2.SelectedItem.ToString());
            }
        }

        private void PopulateDGV(string value)
        {
            //populate with some sample data
            //you will have to get your data by user self from somewhere!
            //THIS code only shows data in DGV when you select:
            //1st and Programme A,
            //2nd and Programme D

            //RESET dataTable:
            if (table != null)
            {
                table.Clear();
                table = null;
            }

            table = new DataTable();
            table.Columns.Add("Column1", typeof(int));
            table.Columns.Add("Column2", typeof(int));
            table.Columns.Add("Column3", typeof(int));

            DataRow dr;
            switch (value)
            {
                case "Programme A": …
Mitja Bonca 557 Nearly a Posting Maven

Try mate, try. Get some books or something. Otherwise you will never learn. I showed you how it needs to be done. You simply study my example and add whats needed.
Come on...

Mitja Bonca 557 Nearly a Posting Maven

You can use a progresBar (you call it loading bar). But it will not be set that the user will see when it will stop. It will just move.

What is the "Counter set"?

Mitja Bonca 557 Nearly a Posting Maven

Hi, you have to create a new Form. Create a method which would start the searching.
Before search begins, start a new thread (so the main one will not be busy while searching). Then create a progressBar, which would show the progress (loading bar).

Somehow you have to figue out what are you searching so, you can define the max lenght of the progreeBar (if not, you will not be able to show procentages; from 0 to 100%).

With the use of Delegates you can update the loading bar (with some label maybe -showing procentages) on the form. Thats about it.
Or instead of creating a new Thread, you can use BackgroundWorker.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Based on my previous code you can do:

//Get the keys which are not in both lists:
var bKeysDiff = sList1.Except(sList2).Select(s => s.Key).ToArray();
foreach (var key in keysDiff) Console.WriteLine(key);
Mitja Bonca 557 Nearly a Posting Maven

This is an example of mine, how do you compare two lists:

//SORTED LISTS:
            SortedList<int, int> sList1 = new SortedList<int, int>();
            for (int i = 0; i < 10; i++)
                sList1.Add(i, i);
            SortedList<int, int> sList2 = new SortedList<int, int>();
            for (int i = 0; i < 5; i++)
                sList2.Add(i * 2, i * 2);

             bool bDiff = sList1.SequenceEqual(sList2);  //boolean value (true, false), if they are equal
            var listDiff = sList1.Except(sList2);        //an actual new list, with the difference in both lists
            foreach (var item in listDiff)
                Console.WriteLine(item);

            Console.ReadLine();
Mitja Bonca 557 Nearly a Posting Maven

And what would you like to know? Only if they are equal?
Or to the the same values back (or to get the vlaues which are not in both array)?

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Just follow the pattern I did for 2 "column". Add new property in the class, and re-work the code in the Dictionary.
No big deal.