Mitja Bonca 557 Nearly a Posting Maven

Ok, into strings. I seperted them with comma. You can do it your way:

string list1 = null;
            string list2 = null;
            using (System.IO.StreamReader sr = new System.IO.StreamReader(@"writePathHere"))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    string[] arrayLine = line.Split(';');
                    for (int i = 0; i < arrayLine.Length; i++)
                    {
                        string value = arrayLine[i];
                        if (i < arrayLine.Length)
                            list1 += value + ", ";
                        else
                            list1 += value;
                        string[] arrayValue = value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        for (int j = 0; j < arrayValue.Length; j++)
                        {
                            string item = arrayValue[j];
                            if (j < arrayValue.Length)
                                list2 += item + ", ";
                            else
                                list2 += item;
                        }
                    }
                }
            }
Mitja Bonca 557 Nearly a Posting Maven

What you are saying it all depends on the sql query. You have to rework the it, with better using "Where" clauses.
I cant help you here, becuase I dont know your db, and neither what exactly and to whom you are sanding emails.

sorry,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Now I understand what are you trying to do. I did a method (custom), and inside of it I created 2 Lists, into 1st go values from 1st array, into 2nd array go values from 2nd array!
This way you have all seperated, and you can do wtih them what ever yozu can.
here` the code:

private void Reading()
        {
            List<string> list1 = new List<string>();
            List<string> list2 = new List<string>();
            using (System.IO.StreamReader sr = new System.IO.StreamReader(@"writePathHere"))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    string[] arrayLine = line.Split(';');
                    for (int i = 0; i < arrayLine.Length; i++)
                    {
                        string value = arrayLine[i];
                        list1.Add(value);
                        string[] arrayValue = value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        for (int j = 0; j < arrayValue.Length; j++)
                        {
                            string item = arrayValue[j];
                            list2.Add(item);
                        }
                    }
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

And where do you want to put the new getted values? To some list?

Mitja Bonca 557 Nearly a Posting Maven

Try to write it as:

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\MyPriject\myDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

Which DB do you have? if you have MsSql express, do exactly this way!! only change the path to the db!

Mitja Bonca 557 Nearly a Posting Maven

Here is a code:

class Class1
    {
        public static Class1 cs;
        public static int s = 0, m = 0;
        ///
        /// The main entry point for the application.
        ///
        [STAThread]
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            int[,] a = new int[10, 10];
            cs = new Class1();
            Console.Write("Enter the order of First Matrix : ");
            s = int.Parse(Console.ReadLine());
            Console.Write("- ");
            m = int.Parse(Console.ReadLine());
            Console.WriteLine();
            Console.WriteLine("\nEnter The value of First Matrice:");
            cs.matrice(a, s, m);
            Console.WriteLine("Matrix entered is:\n");
            cs.arrange(s);
            cs.arrange(a, s, m);
            cs.arrange(s);
            Console.WriteLine("Transpose of Matrix is :\n");
            cs.transpose(a, s, m);
            Console.ReadLine();
        }
        public void matrice(int[,] c, int k, int l)
        {
            for (int i = 0; i <= k - 1; i++)
            {
                for (int j = 0; j <= l - 1; j++)
                {
                    c[i, j] = int.Parse(Console.ReadLine());
                }
            }
        }
        public void arrange(int[,] c, int k, int l)
        {
            for (int i = 0; i <= k - 1; i++)
            {
                for (int j = 0; j <= l - 1; j++)
                {
                    Console.Write(c[i, j] + "\t");
                }
                Console.WriteLine();
            }
        }
        public void transpose(int[,] c, int s, int m)
        {
            int[,] d = new int[10, 10];
            for (int i = 0; i <= s - 1; i++)
            {
                for (int j = 0; j <= m - 1; j++)
                {
                    d[j, i] = c[i, j];
                }
            }
            cs.arrange(s);
            cs.arrange(d, m, s);
            cs.arrange(s);
        }
        public void arrange(int x)
        {
            for (int i = 0; i <= x; i++)
            {
                Console.Write("----------");
            }
            Console.WriteLine();
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

I checked and repair it. This should work now.
BTW: you dont need to create new instances of connectionString and sqlConnection. You can set this only ones (just make sure thats it opened, when its needs to be - but only one, ok?).

Here is the code:

private void TheMethod()
        {
            string sqlString3 = "Select dbo.Requests.managerEmail, dbo.RequestItems.completeDate dbo.Requests.rAuid, dbo.Requests.emailSentToManager " +
                                "from dbo.Requests join dbo.RequestItems on dbo.Requests.rAuid = dbo.RequestItems.request";
            string connString3 = ConfigurationManager.ConnectionStrings[""].ConnectionString;
            SqlConnection sqlConn3 = new SqlConnection(connString3);
            SqlCommand sqlComm3 = new SqlCommand(sqlString3, sqlConn3);

            sqlConn3.Open();
            SqlDataReader reader2 = sqlComm3.ExecuteReader();
            while (reader2.Read())
            {
                string managerEmailAddress = (string)reader2[0];
                string completeDate = (string)reader2[1];
                string request2 = (string)reader2[2];
                bool emailSentToManager = (bool)reader2[3];
                string requestLink2 = "<html>http://ViewEmployeeDetail.aspx.aspx?request=" + request2 + "</html>";

                //then loop if email is not null and emailSentToManager is not true and complete date is not null
                if (!String.IsNullOrEmpty( managerEmailAddress) && !String.IsNullOrEmpty(completeDate) && emailSentToManager != true)
                {
                    //then code to send the email
                    SendEmail(managerEmailAddress, "Click on the following link to the view credentials for your new user: " + requestLink2);
                    //then update database
                    string sqlString4 = "UPDATE Requests SET emailSentToManager= 1 where rAuid= " + request2;
                    SqlCommand sqlComm4 = new SqlCommand(sqlString4, sqlConn3);
                    sqlComm4.ExecuteNonQuery();
                }
            }
            reader2.Close();
            sqlConn3.Close();
        }
Mitja Bonca 557 Nearly a Posting Maven

Maybe its the problem in using the substitution to your database -> |DataDirectory|.


|DataDirectory| (enclosed in pipe symbols) is a substitution string that indicates the path to the database. It eliminates the need to hard-code the full path which leads to several problems as the full path to the database could be serialized in different places. DataDirectory also makes it easy to share a project and also to deploy an application.

For example, instead of having the following connection string:
"Data Source= c:\program files\MyApp\Mydb.sdf"

Using DataDirectory, you can have the following connection string:
“Data Source = |DataDirectory|\Mydb.sdf”

To set the DataDirectory property, call the AppDomain.SetData method. If you do not set the DataDirectory property, the following default rules will be applied to access the database folder:
• For applications that are put in a folder on the user's computer, the database folder uses the application folder.
• For applications that are running under ClickOnce, the database folder uses the specific data folder that is created.

So try changing the string to the full path.

Mitja

Mitja Bonca 557 Nearly a Posting Maven
foreach(string a in array1)
{
    foreach(string b in array2)
    {

    }
}

But it depends, why you will use this kind of array - its better to tell more about why do you need such arrays.
YOu have to know, that 1st string from 1st array, which is in value "a", will go throug all other array, and when will finsih the second array, code will come back to 1st array and selcet the 2nd value from 1sr array and this value will go again through all 2nd array, and so on...

Its better to tell more, or your code will get duplicated, or even worse.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Or you can use delegates, which will call some method on form where you have radioButton, which will be checked before form from where is it called, will close.

Mitja Bonca 557 Nearly a Posting Maven

1st, about you the error "column Price" doesn not belong to table:
YOu have to create columns before filling the table up. YOu do it like:

DataTable table = new DataTable("TableName");
table.Columns.Add(new DataColumn("Price", typeof(decimal))); //specify the correct value type
table.Columns.Add(new DataColumn("Name", typeof(string)));
//then you can fill it up...
;

2nd question about transfering the dataTable to the class:
You can simply pass it as a parameter to some method:
for example you have a method where you fill the table up, and then pass the table as parameter to another method in the same or other class:

class Class1
{
    private void ShowDataFromDataTable()
    {
        DataTable table = FillingDataTable();
        //when code comes back to here, table is fill up with data, 
        //you can use data from it to populate dgv, or something else
    }
    public DataTable FillingDataTable() //modifier can be private if you call it from the same class!
    {
        //example with only 1 column
        DataTable table = new DataTable();
        table.Columns.Add(new DataColumn("1st column", typeof(string)));
        //fill the table
        return table;
    }
}

class Class2
{
    private void ShowDataFromDataTableInOtherClass()
    {         
        DataTable table = FillingDataTable();
        //when code comes back to here, table is fill up with data, 
        //you can use data from it to populate dgv, or something else
    }
}

I hope this is clear example of how to transfer values (data) form method to method, or from class to class in a run time!

Hope this helps,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

If you use "|DataDirectory|" the database has to be embedded in the project. If its not, you have so specify the full path to the it (like : C:\myFolder\MyProject\MyDataBase.sdf)

Mitja Bonca 557 Nearly a Posting Maven

I am glad it did :)
Just dont forget to mark the thread as salved.

bye, ybe
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Even if its a local db, it NEEDS to have a connection string. So find this string and use it (take a look in the upper my example how you use it).

And to answer on yout question, of course it applies on my code too.

PS:You will slowely learn thats better to create dataSets (or dataTables manually) - at least I like it more. Its always good to know whats really going on in the code.

Mitja Bonca 557 Nearly a Posting Maven

The position of the controls can be changed. This can be done with setting the "Anchor" property in the Properties windows. By default all controls are set to allign on TOP-LEFT corner. So when you move bottom righ corner (grow it) all controls will stay on the same position. But if you will allign them by BOTTOM-RIGHT, the controls will move to the right, button corner.
For example, if you set to allign to all 4 corners, the control will grow to all 4 directions.

Try to mess with this option a bit.

But what concerns the size of controls, I`m affraid you wil have to set the manually.
There is not so much code, you only need to do a common common code with some if/else statements, which will look on for how much the form has shrinked/grown and the code will re-set the size of controls.

Hope this helps a bit,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

If you have a dataBase in your project, you sure have a file called App.Config. You will find it in Solution explorer. There you have a connection string written, and also the name of the connection string. This is en example:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
  </configSections>
  <connectionStrings>
    <add name="myConnectionString"
        connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\AppsTest\MyProject\mydataBaseName.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

so, when you have set the path to the dataBase and the it`s name(C# can do it by him self as well, while creating dataBase), you can easily use SqlConnection method.
I will show you an example how you have to do it, regarding your example.
But before going into the code, you need to add a new namespace to the class where you will use sql connection:
- in solution explorer right click on "References", and choose "Add reference"
- look for System.Configuration (and select it)
- on the top of the class there are namespaces which you use them - you have to add: using System.Configuration;

Now we can go to the code:

class YourClass
    {
        private static string sqlConn = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
        //myConnectionString must be the same name as it is in the app.Config file!

           public static string[] SelectUser(string userName)
           {
                string value1 = null;  //username
                string value2 = null;  //nickname
                using (SqlConnection conn = new SqlConnection())
                {
                   string query = "select username, nick from [user] where username = @user";
                    using (SqlCommand cmd = new SqlCommand(query, conn))
                    {                       
                        cmd.Parameters.Add("@user", SqlDbType.VarChar, …
Mitja Bonca 557 Nearly a Posting Maven

That's not true. You can send sms for free using SMTP (as long as you can find your opearator's sms gateway).
http://en.wikipedia.org/wiki/List_of_SMS_gateways

Yes, I know that, but this is not possible in my Country (Slovenia).

Mitja Bonca 557 Nearly a Posting Maven

I agree with Hyperion.
This is us getting no where. I assume everyone of us is so inteligent these days, that can use "The google wonder" to find the code, which would make his life easier.
We are here to help ppl with their own specific issues, and I am willing to help them with my best efforts. I expect the same from all of you who are answering here.
What concers the thread creator, prayag.419:
If you want some help from us, please give us some more info about your project. Maybe some of the code where you have issues, or at least explain precisly what would you like to do, in case if you have nothing to give us. We cannot only assume what would you like, ok?

So please show us some good will.
regards,

Mitja

ddanbe commented: Good advice +8
Mitja Bonca 557 Nearly a Posting Maven

I did a bit more of a code, to show you how its done.
You only have to put these controls on your form:
- 2 listboxes
- 1 textBox
- 1 button

Code:

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 Nov28Exercise
{
    public partial class Form1 : Form
    {
        List<string> list;
        public Form1()
        {
            InitializeComponent();
            list = new List<string>();
            PopulatingTextBox1();
        }

        private void PopulatingTextBox1()
        {
            string[] array = new string[] { "one@test.com", "@test.com", "@contoso.com" };
            for (int i = 0; i < array.Length; i++)
            {
                string value = array[i];
                string[] seperate = value.Split(new string[] { "@" }, StringSplitOptions.None);
                if (seperate[0] == "")
                    this.listBox1.Items.Add(value);
            }
        }

        private void PopulatingTextBox2(string value)
        {
            bool bInserting = true;
            foreach (string item in list)
            {
                if (item == value)
                {
                    bInserting = false;
                    MessageBox.Show("The e-mail \"" + value + "\" is already in the list\nIt will not be inserted!");
                    break;
                }
            }
            if (bInserting)
            {
                this.listBox2.Items.Add(value);
                list.Add(value);
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.listBox1.SelectedIndex > -1)
            {
                string value = this.listBox1.SelectedItem.ToString();
                this.textBox1.Text = value;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string value = this.textBox1.Text;
            string[] array = value.Split(new string[] { "@" }, StringSplitOptions.None);
            if (array[0] != "")
                PopulatingTextBox2(value);
            else
                MessageBox.Show("Please correct the e-mail address before saving it into the list.");
        }
    }
}
Mitja Bonca 557 Nearly a Posting Maven

This is the code which populates the textBox with only wanted items (the ones which dont have the name infront of sing @):

private void PopulatingListView()
        {
            string[] array = new string[] { "one@test.com", "@test.com", "@contoso.com" };
            for (int i = 0; i < array.Length; i++)
            {
                string value = array[i];
                string[] seperate = value.Split(new string[] { "@" }, StringSplitOptions.None);
                if (seperate[0] == "")
                    this.listBox1.Items.Add(seperate[1]);
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

If you have all information required, I can help you out creating it.

Mitja Bonca 557 Nearly a Posting Maven

LOL... why bothering...

Mitja Bonca 557 Nearly a Posting Maven

This is the right way of using database and insert command:

try
{
 using (SqlConnection sqlConn = new SqlConnection( connectionString ) ) 
 {
  //query string and opening the connetion
  sqlConn.Open();
 }
}
catch ( Exception ) 
{
 //catch errors
}
finally
{
 //closing connection
}
 

Example:

private static void CreateCommand(string queryString, string connectionString)
{
  using (SqlConnection connection = new SqlConnection(connectionString))
  {
    string insertString  = "INSERT INTO MyDataTable VALUES(specify all values you want to insert here) " +
                           "WHERE if where clause needed specify it here";
    SqlCommand command = new SqlCommand(insertString, connection);
    command.Connection.Open();
    command.ExecuteNonQuery();
  }
}

Is this what you wanted?

Mitja Bonca 557 Nearly a Posting Maven

What are we talking here? Or DataBase or DataTable? This is no way you will insert data to dataBase.
For inserting data into database, you need on open sql connection and created sql command, which will insert data.

Didn`t you confuse it witl dataTable (or dataSet)?

Mitja Bonca 557 Nearly a Posting Maven

kishor20, I will go back to your 1st post...
I would suggest you not to re-build or trying using some of pre-made project, becuase this is very time consuming, and you will never have all what you had needed on the beginning, so...
it`s bette to star from the beginning, and I would agree with adatapost`s who said that you need to have a decent understanding of the .net framework, C# language and other technologies, to start with a project like you want it to do.
So, if you want to start with, 1st you need to have some knowledge about coding, but before statring with the code, you need to create a database structure (I hope the program will have it).

And here you are the only one who can get and capture all the information required. You work there (or at least you know someone there), so you can get all whats needed to create the database. Especially on the beginning, you have to get all the info needed, to design the dataBase structure and then we can help you out with desigining the program it self (classes and stuff).
You have to start doing the project systematically - one step at the time, becuase this project isn`t a piece of a cake (as far as I can see).
To create the database, its good to create some of the model (on the paper, or with pc - there is plenty of …

Mitja Bonca 557 Nearly a Posting Maven

SMS is not for free. This will not do. There are ways but you will have to pay the service. Are you still intereseted?

Mitja Bonca 557 Nearly a Posting Maven

Let me know if is was in any help. If not (completely), please tell me what is needed to repair, ok?
cya
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Link to the project is HERE.
I hope this is what you hae been looking for.

cya

Mitja Bonca 557 Nearly a Posting Maven

Yes, close to the finish. I only have to do the import.

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

These errors has nothing to do with the connection string to your database. Your code is a bit weird.
Do you use "using" statement while accessing to db?

like this:

try
{
 using (SqlConnection sqlConn = new SqlConnection( connectionString ) ) 
 {
  //query string and opening the connetion
  sqlConn.Open();
 }
}
catch ( Exception ) 
{
 //catch errors
}
finally
{
 //closing connection
}

Example:

private static void CreateCommand(string queryString, string connectionString)
{
  using (SqlConnection connection = new SqlConnection(connectionString))
  {
    SqlCommand command = new SqlCommand(queryString, connection);
    command.Connection.Open();
    command.ExecuteNonQuery();
  }
}

This is the best approach, I would say.

To ensure that connections are always closed, open the connection inside of a using block, as shown in the following code fragment. Doing so ensures that the connection is automatically closed when the code exits the block.

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

Xml is nothing harder to cope with, then a simple txt file, only that its screpted.
Please ust go over the lines that I have created in the previous post, and you will see how easy can all be - the most importatn in coding is approach. Take slow steps forward, not all at ones.
Read some literature of how to use xml, google knows all.
But if you still insist, I will do a particual example onl for you - exporting to xml and importing them back to dgv.
ok?

Mitja Bonca 557 Nearly a Posting Maven

What do you mean 4 columns? 2 on the form_load event and 2 on button click?

Look, this way we are getting no where. 1st of all would be good that you study some literature, that you will get the basics covered.
You cant just do import of the xml file, not knowing what are you importing and where. I will give you now some points how you need to approach to this project:
- create dgv (with all the columns)
- fill dgv with some data
- do the export to xml
- finaly: only now you can do import of the pre-exported xml file back to dgv.

You got now the whole picture. Please don`t jump things, cause we wont get any further. I am trying to help you out here, but your knowledge is apperently not on the level to cope with this kinda task.
So i really suggest you, please learn some basics, start with more easier things, if this is too much for you atm. One step at a time.
Programming is a huge library of knowledge, and you wont get it over night. Especially you wont learn it, if I will do all the work.

So, PLEASE if you want me to help you (or someone else here) out with this project, go by the points I`ve stated up there. Step by step. And if there will be any problem let me know (create …

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

You still didnt show me where it come to the error.
Take a look at this simple example of to populate dgw from xml file:

private void Form1_Load(object sender, EventArgs e)
 {
           XmlDataDocument xmlDatadoc = new XmlDataDocument();
            xmlDatadoc.DataSet.ReadXml("C:\\books.xml");
            DataSet ds = new DataSet("Books DataSet");
            ds = xmlDatadoc.DataSet;
            dataGridView1.DataSource = ds.DefaultViewManager;
            dataGridView1.DataMember = "Book";
  }
Mitja Bonca 557 Nearly a Posting Maven

Show me the code, and point on the row where the error occures?
Your problem is that you try to fill the data into uncreated columns or rows.

Mitja Bonca 557 Nearly a Posting Maven

Not now, I have to go.. really. I someone else wont help, I`ll do it tomorrow.
Just for into: oyou have to set the control`s modifier as public, and this is not good - to acces to control over classes.
Maybe you can figure out how it goes.
Sorry, regards,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

No, because the control which you want to update is on form1. So method InvokeRequired() has to execute on form1.
There are ways to call textBox1 from MyClass, but I wouldn`t recomend you that - seriousely.

Hope this helps.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

So what do you think about this? This code is actually calling From MyClass, a method on Form1 - like you said.

public partial class Form1 : Form
    {
        int oldValue;
        delegate void MyDelegate(int value);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(StartNewThread));
            thread.Start();
        }

        private void StartNewThread()
        {
            MyClass myClass = new MyClass(this);
            int a = Convert.ToInt32(textBox1.Text);
            int b = Convert.ToInt32(textBox2.Text);
            int[] array = new int[] { a, b };
            myClass.Calculating(array);            
        }

        public void DoWork(int value)
        {
            this.textBox3.Invoke(new MyDelegate(ShowResults), new object[] { value });           
        }

        private void ShowResults(int value)
        {
            textBox3.Text = value.ToString(); 
        }
    }
    class MyClass
    {
        Form1 form1;
        public MyClass(Form1 _form1)
        {
            form1 = _form1;
        }

        public void Calculating(int[] array)
        {
            int value = array[0] * array[1];
            form1.DoWork(value);
        }
    }

Are you happy now?
Of not, I will need some more info to help you out.

Mitja
Mitja Bonca 557 Nearly a Posting Maven

So you would like from MyClass update listBox on Form1?
Why? This doesnt make any sence. Especially not in this kind of example we are doing. Do you have any other reasons to do so?

Mitja Bonca 557 Nearly a Posting Maven

Ok, I did what I think its best for you. I hope it will suits oyur needs. The code calculates values from 2 textBoxes and inserts the result into 3rd textBox. Calculation is done by creating a new thread. Showing the result needs a delegate.
All you have to do is to insert 3 textBoxes and a button on the form and insert integers (numbers only - becuase the code has no error cahtching yet) into textBox1 and textBox2. Then press button.

Its good to put some breakpoints in the code, that you will see how the code goes, and then go line by line with F11. This is the code:

public partial class Form1 : Form
    {
        delegate void MyDelegate(int value);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(StartNewThread));
            thread.Start();
        }

        private void StartNewThread()
        {
            MyClass myClass = new MyClass();
            int a = Convert.ToInt32(textBox1.Text);
            int b = Convert.ToInt32(textBox2.Text);
            int[] array = new int[] { a, b };
            int c = myClass.Calculating(array);
            this.textBox3.Invoke(new MyDelegate(ShowResults), new object[] { c });
        }

        private void ShowResults(int value)
        {
            textBox3.Text = value.ToString();
        }
    }

    class MyClass
    {
        public int Calculating(int[] array)
        {
            return array[0] * array[1];
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

I did an example which starts a new form2 (form2 opens) and sends some text over to a listBox (on form2).
Take a look at this code. If you cannot midify it to your needs, let me know, I`ll do exactly what you want:

//form1:
 public partial class Form1 : Form
    {
        delegate void MyDelegate(string msg);
        public static bool bForm2Opened { get; set; }
        Form2 form2;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {          
            if (!bForm2Opened)
                StartNewThread();
            else
                OpenForm2();           
        }

        private void StartNewThread()
        {
            form2 = new Form2();
            form2.Show();
            Thread thread = new Thread(new ThreadStart(OpenForm2));
            thread.Start();
            bForm2Opened = true;   
        }

        private void OpenForm2()
        {
            string value = this.textBox1.Text;
            form2.DoWork(value);
            //clearing textBox on form1:
            this.textBox1.Invoke(new MyDelegate(ClearingTextBox), new object[] { null });            
        }

        private void ClearingTextBox(string msg)
        {
            this.textBox1.Text = null;
            this.textBox1.Focus();
        }
    }

//form2:
 public partial class Form2 : Form
    {
        delegate void MyDelegate(string msg);

        public Form2()
        {
            InitializeComponent();
        }

        public void DoWork(string msg)
        {
            this.listBox1.Invoke(new MyDelegate(PopulatingListBox), new object[] { msg });                
        }

        private void PopulatingListBox(string msg)
        {
            this.listBox1.Items.Add(msg);
        }

        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            Form1.bForm2Opened = false;
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

So when you will create a new thread?
Thats important to know, that you know when to open new Form.
In use case new thread is starting all over again, when trying po send a value into listBox on Form2.
What about if you want to send 2nd value? Your code cannot do it.

Do you Want to create a new Thread and open Form2? This thread has to remain opened until form2 is opened?
When form2 closes, the thread closes as well?

Is that how it should be?

Mitja Bonca 557 Nearly a Posting Maven

If you have 2 columns in the dataTable then to populate dgv simpe create a method and call it (in the method bellow I pass the parameter of dataSet):

private void PopulatringDGV(DataSet ds)
        {
            int row = 0;
            int column = 0;
            foreach (DataRow dr in ds.Tables[0].Rows) //or: Tables["TableName"]
            {
                column = 0;
                this.dgv[column, row].Value = dr[0].ToString();
                column++;
                this.dgv[column, row].Value = dr[1].ToString();
                row++;
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

This is the solution, and you do not need to use any threads. This will only complicate things (simples you dont need to use them).
This is the simple example of how to pass data (parameters) over forms and being showed:

//FORM 1:
 public partial class Form1 : Form
    {
        public static bool bForm2Opened { get; set; }
        Form2 form2;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string value = textBox1.Text;
            if (!bForm2Opened)
            {
                form2 = new Form2();
                form2.Show();
                bForm2Opened = true;
            }
            form2.PopulatingListBox(value);
            //clearing textBox:
            textBox1.Text = null;
            textBox1.Focus();
        }
    }

//FORM 2
 public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public void PopulatingListBox(string value)
        {
            listBox1.Items.Add(value);
        }

        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            Form1.bForm2Opened = false;
        }
    }

Hope it helps, if not let me knows,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

i get an error on:

private void button1_Click(object sender, EventArgs e)
{
    ds.Tables["Record"].Rows.Add(textBox1.Text, textBox2.Text);
}

You didnt specify to which column of the dataTable belong values form textBox1 and textBox2.
btw, do you intend to insert both values into one column, or both values in seperated columns?

Otherwise, inserting values into columns of dataTabele of dataSet goes like this:

private void PopulateDataSet()
        {
            using (DataSet ds = new DataSet())
            {
                using (DataTable table = new DataTable("1stTable"))
                {
                    DataRow newRow;
                    //creating column of the dataTable:
                    table.Columns.Add(new DataColumn("Column1", typeof(string)));
                    table.Columns.Add(new DataColumn("Column2", typeof(string)));
                                        
                    string value1 = "valuue1"; //use textBox1.Text
                    string value2 = "value2";  //use textBox2.Text
                    //and so on...
                    
                    string[] array = new string[] { value1, value2 };
                    int column;

                    for (int i = 0; i < array.Length; i++)
                    {
                        column = 0;
                        newRow = table.NewRow();
                        newRow["Column1"] = array[i];
                        column++;
                        newRow["Column2"] = array[i];
                        //adding row into dataTable:
                        table.Rows.Add(newRow);
                    }
                    //adding dataTable to dataSet:
                    ds.Tables.Add(table);
                }
            }
        }

But I would adivse you not to use dataSet, if you dont have more then 1 dataTables at ones to use. It will only complicate things.

Hope it helps,
if questions, please ask,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

No, if you want to update view, you will have to re-populate dgv.
You can do it on 2 ways:
1. create dataTable and bind it to the dataSource of dgv
2. crete dataTable and populate dgv manually (column by column, row by row)

The best way of populating dgv is to fill dataTable with sql adapter (in sql query), and then use these data in dataTable.

Hope it helps,
happy coding
If you need any asistance, let me know, and please specify exactly what you need and if possible give us some of your code.

Mitja Bonca 557 Nearly a Posting Maven

This is the simpleast and easiest way to get the data from DB to dgv:

private void Form1_Load(object sender, System.EventArgs e)
{
    // Bind the DataGridView to the BindingSource
    // and load the data from the database.
    dataGridView1.DataSource = bindingSource1;
    GetData("select * from Customers");
}

private void GetData(string selectCommand)
{
    try
    {
        // Specify a connection string. Replace the given value with a 
        // valid connection string for a Northwind SQL Server sample
        // database accessible to your system.
        String connectionString =
            "Integrated Security=SSPI;Persist Security Info=False;" +
            "Initial Catalog=Northwind;Data Source=localhost";

        // Create a new data adapter based on the specified query.
        dataAdapter = new SqlDataAdapter(selectCommand, connectionString);

        // Create a command builder to generate SQL update, insert, and
        // delete commands based on selectCommand. These are used to
        // update the database.
        SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

        // Populate a new data table and bind it to the BindingSource.
        DataTable table = new DataTable();
        table.Locale = System.Globalization.CultureInfo.InvariantCulture;
        dataAdapter.Fill(table);
        bindingSource1.DataSource = table;

        // Resize the DataGridView columns to fit the newly loaded content.
        dataGridView1.AutoResizeColumns( 
            DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
    }
    catch (SqlException)
    {
        MessageBox.Show("To run this example, replace the value of the " +
            "connectionString variable with a connection string that is " +
            "valid for your system.");
    }
}

Some additional info you can find here: http://www.switchonthecode.com/tutorials/csharp-tutorial-binding-a-datagridview-to-a-database
REMEMBER: nothing will be gifted to you, all you will have to learn by your self. So, please be good, and do some teaching. Google knows many, many things as well.
And good …

Mitja Bonca 557 Nearly a Posting Maven