Mitja Bonca 557 Nearly a Posting Maven

There is maybe another solution:

Private Shared Sub Main()
	Application.EnableVisualStyles()
	Application.SetCompatibleTextRenderingDefault(False)
	Application.Run(New Form1())
	' Form1 in this Application.
	Application.Run(New Form2())
	' Form2 in this application.
End Sub

.. if you want Form2 to open after Form1 exits. There's no going back. When Form2 closes, the programs end.

Mitja Bonca 557 Nearly a Posting Maven

You cant. The Form2 was stared as the Main form in the Main method. You can only Hide it (use this.Hide() method), if you will close it, the whole application will close.

Mitja Bonca 557 Nearly a Posting Maven

Here is a code example:

public class ArrayComparer : System.Collections.IComparer
{
int ix;
public ArrayComparer(int SortFieldIndex)
{
ix = SortFieldIndex;
}

public int Compare(object x, object y)
{
IComparable cx = (IComparable)((Array)x).GetValue(ix);
IComparable cy = (IComparable)((Array)y).GetValue(ix);
return cx.CompareTo(cy);
}
}


/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{

string[][] lines = new string[4][];
lines[0] = new string[] {"1","a","d"};
lines[1] = new string[] {"2","b","c"};
lines[2] = new string[] {"3","c","b"};
lines[3] = new string[] {"4","d","a"};

foreach (string[] line in lines)
{
Console.WriteLine(line[0]);
}
System.Array.Sort(lines,new ArrayComparer(2));
foreach (string[] line in lines)
{
Console.WriteLine(line[0]);
}

}
Mitja Bonca 557 Nearly a Posting Maven

Hi, check here for solution.

Mitja Bonca 557 Nearly a Posting Maven

So go on that website, look for sql Server 2008 connection string, and use it (copy paste it into your code; change with the existing one).
Conn. string has to include IP Address, username and password.

Mitja Bonca 557 Nearly a Posting Maven

Yes, you have to attach the DB.
Which sql Server will use that person for whom you are doing this application?
Its important to know, because based on that you require an appropriate connection string. Connection strings can be found here.

As said previously, crystal reports will work fine, you only have to install them on the customer`s computer. DataBase will be accessed with the appropraite connection string.

Mitja Bonca 557 Nearly a Posting Maven
int userID;

private void button_GetIdNum(object sender, EventArgs e)
{
    string userName = textBox1.Text; //this is an example, from where you get the name
    using(SqlConnection sqlConn = new SqlConnection("connString")) 
    {
         using(SqlCommand cmd = new SqlCommand())
         {
               cmd.CommandText = @"SELECT idnum FROM tablename WHERE name = @name";
               cmd.Parameters.Add("@name", SqlDbType.Int).Value = userName;
               cmd.Connection = sqlConn;               
               sqlConn.Open();
               using(SqlDataReader reader = cmd.ExecuteReader())
               {
                    if(reader.Read())
                    {
                        userID = (int)reader[0];  //now you have a form variable filled up
                        //and you can use it in a whole form (class) 
                        MessageBox.Show(String.Format("Id found. User with name {0} has id {1}.", userName, userID.ToString()));
                    }
                    else
                        MessageBox.Show("There is no user with this Id in the dataBase.");
               }
         }
    }
}
Mitja Bonca 557 Nearly a Posting Maven

So you have to go there and install the SQL Server on his computer (or where ever he wants to have it). But if its a Server version, probably will not be on the same computer as the application which you are making.

BTW: how are you connected to the server now? What connection string do you use?

Mitja Bonca 557 Nearly a Posting Maven

Hi,
you can have a server like where its now, but if you want that the application will work, the 1st important thing is that the server is running.
2nd whats important is the connection string. It must include the server`s IP address, so the application on the other computer can access to the dataBase on server.
Nothing about SQL Server is not needed to be included in the Published version of the application.

Crystal reports are part of the application, and must be included in the prerequsities, because they must be installed on the computer where application will be installed.
This is about it.

Mitja Bonca 557 Nearly a Posting Maven

This post of yours has no much of a point.
"the selected value from my database"

There is no such thing as selected value in dataBase.

Please, be more specific of this issue of yours.

Mitja Bonca 557 Nearly a Posting Maven

Let us see this code...

Mitja Bonca 557 Nearly a Posting Maven

Why you create a new dgv? The new one is again not created.Try this one:

con = New OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;" & _
"Data Source=C:/Users/Space Era/Documents/perf.mdb")
            con.Open()
            Dim dgv As New DataGridView()            
            'here you can set Size, Location, ... and other properties too (but it would be good to create a new, seperate method of DGV creation
            Me.Controls.Add(dgv)
            Dim dataset1 As New DataSet()
            Dim sqlstring As String = "select * from data where Date >= '" & DateTimePicker2.Value & "' and Date<= ' " & DateTimePicker1.Value & "'"
            cmd = New OleDbCommand(sqlstring, con)
            Dim oledbdataadapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(cmd)
            oledbdataadapter1.Fill(dataset1, "data")
 
            datagridview1.DataSource = dataset1.Tables("data")
Mitja Bonca 557 Nearly a Posting Maven

Try this code:

Private table As DataTable
Public Sub New()
	InitializeComponent()

	table = New DataTable("myTable")
	table.Columns.Add("column 1", GetType(String))
	table.Columns.Add("column 2", GetType(String))
	table.Rows.Add("a1", "b1")
	table.Rows.Add("a2", "b2")
	table.Rows.Add("a3", "b3")
	table.Rows.Add("a4", "b4")
	dataGridView1.DataSource = New BindingSource(table, Nothing)
End Sub

Private Sub button1_Click(sender As Object, e As EventArgs)
	Dim selectedRow As DataRow = table.Rows(dataGridView1.CurrentRow.Index)
	Dim newRow As DataRow = table.NewRow()
	newRow.ItemArray = selectedRow.ItemArray
	' copy data
	table.Rows.Remove(selectedRow)
	table.Rows.InsertAt(newRow, 0)
End Sub

as you can see the dataTable is bound to datagridview, so you can see the actual results, when selecting a row and pressing a button. The selected row will move to the top of DGV (the same as in dataTable).
If you want to use the code in dataSet, just create is, and add a dataTable to it.

mrbungle commented: Thanks for your help and time! Good code! +2
Mitja Bonca 557 Nearly a Posting Maven

Hi,
1st, point is that you have the same columns, ok its not really necessary, but its good when you want to copy a row from on dataGrid to anoter to have at least the same number of columns and that are the same type (even all can be parsed as objects).
So this is the code example:

private void button1_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                dataGridView2.Rows.Add();
                int newRow = dataGridView2.Rows.Count - 1;
                foreach (DataGridViewCell cell in row.Cells)
                {
                    dataGridView2[cell.ColumnIndex, newRow].Value = cell.Value;
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

You didnt add the newly created dataGridiView to the form. Do it this way:

Dim dgv As New DataGridView()
Me.Controls.Add(dgv)
'this line you are missing
Mitja Bonca 557 Nearly a Posting Maven

Hi,
check for an example code here, and use C# to VB converter.

Mitja Bonca 557 Nearly a Posting Maven

Do you want to set "u" property to field "i"?
If so, you can do it this way:

int i = 9;
int o = 8;

private U;
int u
{
    get { return U; }
    set { U = i; }
}

If you will get i in u property (like you showed), then there is no point in having u property at all.

Mitja Bonca 557 Nearly a Posting Maven

1st time you SET it.
2nd time oyu get it.

Simple. If you want to read, 1st you have to set it, then when is set, you can ge it.

Example:

class a1
{
     a2 a;
     private void methodA()
     {
          a = new a2();
          a.MyText = "something to set"; //set
     }

     private void methodB()
     {
          string text = a.MyText; //get
     }
}

class a2
{
     public string MyText { get; set; }
}
Mitja Bonca 557 Nearly a Posting Maven

He is telling you the same as I did. Not possible. But you can take a look into my last post, where I gave you a work around solotion.

Mitja Bonca 557 Nearly a Posting Maven

hi Mitja, firstly thanks for the remind of the word 'form', I will remind it.
The class is created below the Form1 or I needs to add it from the Project >> Add Class ?

No, not need it. Ok, you can do that, but you can write this kind of class on the Form1, take a look at this example:

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;
using System.Data.SqlClient;

namespace Jun28Test1
{
    public partial class Form1 : Form
    {
        DataTable table;
        public Form1()
        {
            InitializeComponent();
        }

        //rest of the code on Form1
    }

    static class MyClass
    {
        public static string MyText { get; set; }
    }

This is all on one *.cs file - like you see

So no need to create a brand new *.cs file. But if you want, you can do it.

Mitja Bonca 557 Nearly a Posting Maven

lol,
he is not a genious. He only knows more.

jfarrugia btw, next time what is the code, you have to put it into code brackets!
I hope you understand (forum rules).

Mitja Bonca 557 Nearly a Posting Maven

You are welcome.
bye

Mitja Bonca 557 Nearly a Posting Maven

As I understand Your, you like to send value of text to textbox of other form.

go to the designer of the destination form and find the code for text change the access specifier from private to public
Now

//create object of destination
form2 f =new form2;
f.textbox.text="Your text";
f.show();

Bad, bad example.
What you did is to set control and public (textBox), and this is sometihng the worst you can do.
And besides, he said he wasnt to pass data over 3 forms, not only form 1st to 2nd, but from 1st, over 2nd, to 3rd form. And this is not gonna work.

Take a look at mine Simple and working example.

Mitja Bonca 557 Nearly a Posting Maven

This is not possible. You can color the text, but only int one color.
If you want to have two or more color, there is a work-around.
Create labels, and put them in the position of the groupBox text. Color the what eve you want.

Mitja Bonca 557 Nearly a Posting Maven

This is not how we do the method in "correct" way. I put the correct word into quotation marks, becuase everything is correct as long as the code works, but there wre have some rules we have to follow, so the code is more appropriate and looks better and works better (better performance - which is one of the goals of every programmer).
So try to do it this way:

static string concString = @"Data Source=BJ-PC\\SQLEXPRESS;Initial Catalog=new;Integrated Security=SSPI";
        public void getLastMemID()
        {
            int ID = 0;
            using (SqlConnection CN = new SqlConnection(concString))
            {
                CN.Open();
                string sqlQuery = @"SELECT MAX(ImageId) FROM ImagesStore";
                using (SqlCommand com = new SqlCommand(sqlQuery, CN))
                {
                    using (SqlDataReader dr = com.ExecuteReader())
                    {
                        if (dr.Read())
                            ID = (int)dr[0];
                    }
                }
            }
            if (ID > 0)
                MessageBox.Show("Max id is " + ID.ToString());
            else
                MessageBox.Show("There is no id in this table (its an empty table)");
        }
Mitja Bonca 557 Nearly a Posting Maven

1st of all, there is no word about Interfaces - there is a completely different expression. You wanna talk aobut Forms. Ok? So, please in the future use this term - Form.
What you can do, is to create a seperate class, with property (property is a "field" which uses get set accessors). And mark the property as static (with static modifier).

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

        private void button1_Click(object sender, EventArgs e)
        {
            //set the static property with the text you want:
            MyClass.MyText = textBox1.Text;
            Form2 f2 = new Form2();
            f2.Show();
            this.Hide();
        }
    }

    static class MyClass
    {
        public static string MyText { get; set; }
    }

    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
            //get data from static class from where ever you want:
            //form2 was in between, but form2 has nothing to do with passing data
            //so we can call the GET accessor from where every want - from form3:
            textBox1.Text = MyClass.MyText;
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

An interface is a reference type object with no implementation. You can think of it as an abstract class with all the implementation stripped out and everything that is not public removed. Abstract classes are classes that can not be instantiated. No properties or methods are actually coded in an interface, they are only defined. So the interface doesn't actually do anything but only has a signature for interaction with other classes or interfaces.

Check for some simple examples here.

Mitja Bonca 557 Nearly a Posting Maven

Remove that name out of connection string, use only this:

Data Source=\sqlexpress; AttachDBFilename=F:\\Projects\\MyProj\\FirstProj\\bin\\Debug\\Database\\MyDB.mdf;Integrated Security=ture; User Instance=true;

or:

"Data Source=.\\SQLEXPRESS;AttachDBFilename=F:\\Projects\\MyProj\\FirstProj\\bin\\Debug\\Database\\MyDB.mdf;Integrated Security=ture; User Instance=true;
Mitja Bonca 557 Nearly a Posting Maven

Yes, take a look at this example here.

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

Go to your Properties of the Project (in solution explorer right mousr click on your project name).
It will open a new tabPage of Properties. Go to "Publish" tab. Now select all the prerequisites you want to install. And ot the bottom select when (how) you want them to be installed.
You can select them to be installed from the internet, or from th application. If you select the last, you have to put all these prerequisites into your application folder.
This ia aobut it.

Mitja Bonca 557 Nearly a Posting Maven

You would have to add a DataGridViewRadioButtonColumn, either in designmode or at runtime. Use the CustomDataGridView instead of the DataGridView when you design the form.

public class DataGridViewRadioButtonColumn : DataGridViewTextBoxColumn  
    {  
        internal const int radioButtonSize = 14;  
 
        public DataGridViewRadioButtonColumn()  
            :base()  
        {  
            this.ReadOnly = true;  
        }  
 
        internal static void Paint(Graphics g, Rectangle cellBounds, bool state)  
        {  
            cellBounds.Inflate(-1, -1);  
            Brush drawBrsh = new SolidBrush(SystemColors.Control);  
            g.FillRectangle(drawBrsh, cellBounds);  
            cellBounds.Inflate(0, -((cellBounds.Height - radioButtonSize) / 2));  
            ControlPaint.DrawRadioButton(g, cellBounds, (state) ? ButtonState.Checked : ButtonState.Normal);  
            drawBrsh.Dispose();  
        }  
    }  
 
    public class CustomDataGridView : DataGridView  
    {  
        protected override void OnCellClick(DataGridViewCellEventArgs e)  
        {  
            if (e.RowIndex > -1)  
            {  
                DataGridViewCell cell = this[e.ColumnIndex, e.RowIndex];  
                if (cell.OwningColumn is DataGridViewRadioButtonColumn)  
                {  
                    if (cell.FormattedValue.ToString().Length == 0)  
                    {  
                        for (int i = 0; i < this.RowCount; i++)  
                        {  
                            this[e.ColumnIndex, i].Value = string.Empty;  
                        }  
                        cell.Value = "Selected";  
                    }  
                }  
            }  
            base.OnCellClick(e);  
        }  
 
        protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)  
        {  
            if ((e.RowIndex > -1) && (e.ColumnIndex > -1) &&  
                (this.Columns[e.ColumnIndex] is DataGridViewRadioButtonColumn))  
            {  
                e.PaintBackground(e.CellBounds, true);  
                DataGridViewRadioButtonColumn.Paint(e.Graphics, e.CellBounds,  
                    (e.FormattedValue.ToString().Length > 0));  
                e.Handled = true;  
            }  
 
            base.OnCellPainting(e);  
        }  
    }
Mitja Bonca 557 Nearly a Posting Maven

And here is one link to custom button control.

Mitja Bonca 557 Nearly a Posting Maven

You can create your own boolean variable, which will be set accordinglly:

string query1 = @"update trainn set Adultno=Adultno-1 where ID=@pram1 and adult=@pram2 and Adultno>0";
            string query2 = @"update trainn set childno=childno-1 where ID=@pram1 and child=@pram2 and childno>0";
            string[] queriesArray = new string { query1, query2 };
            bool bAllOK;
            foreach (string query in queriesArray)
            {
                sqlCmd = new SqlCommand();
                sqlCmd.Connection = sqlCon;
                sqlCom.CommandText = query;
                if (sqlCon.State != ConnectionState.Open)
                    sqlCon.Open();
                sqlCmd.Parameters.AddWithValue("@pram1", textBox3.Text);
                try
                {
                    sqlCmd.ExecuteNonQuery();
                    bAllOK = true;
                }
                catch
                { 
                //show your error message
                    bAllOK = false;
                    break;
                }
            }
            if (bAllOK)
                MessageBox.Show("All ok");
Mitja Bonca 557 Nearly a Posting Maven

You can do:

string query1 = @"update trainn set Adultno=Adultno-1 where ID=@pram1 and   
  adult=@pram2 and Adultno>0";
string query2 = @"update trainn set childno=childno-1 where ID=@pram1 and  
  child=@pram2 and childno>0";
string[] queriesArray = new string { query1, query2 };
foreach(string query in queriesArray)
{    
     sqlCmd = new SqlCommand();
     sqlCmd.Connection = sqlCon;
     sqlCom.CommandText = query;
     if(sqlCon.State != ConnectionState.Open)
          sqlCon.Open();
     sqlCmd.Parameters.AddWithValue("@pram1", textBox3.Text);
     sqlCmd.ExecuteNonQuery();
}
sqlCon.Close();
Mitja Bonca 557 Nearly a Posting Maven

So create a new table, and inside of it create some columns: AbsenceID, StudentFK, Date.
This means each row will have its only id (primary key), foreign key to the Students table, and an actual absendce date.
So you will have this kind of structure:

Student: StudentID, Name, Age,... (and no Absence)
Absence: AbsenceID, StudentFK, AbsenceDate
Mitja Bonca 557 Nearly a Posting Maven

Do you get any data into DataTable? Use a break point, hover the mouse ovher "dat" variable, and click on Magnifying glass to see if there is any data inside. If its not, your query is not corrct, or database is empty.

Check that 1st.

Mitja Bonca 557 Nearly a Posting Maven

Do you want to create a DataBase out of these data?
I think it would be good, and then create some classes, like Student, Class, and so on if needed.
It would still be good if you tell us more what are you trying to do, a complete application for running the school maybe?

Mitja Bonca 557 Nearly a Posting Maven

Same here ddanbe. I started in early 2009, and same as you. But even if I like programming, I am still far from being a professional progamer. It takes time, thats it.

Mitja Bonca 557 Nearly a Posting Maven

LOL, there is no such thing! Sorry, you came on the wrong place.

Best way to get knowledge is to try to use it in practice. SO has a plenty of questions about C# books/sites/tutorials. Learning pattern is really simple: read a little bit of information on C# and try to write small program that uses this information. Don't try to understand the whole thing at once, grok it by small pieces and in a couple of weeks you'll get enough knowledge to write meaningful programs.

----------------
But in case, if you want to spend a couple of days more then only a few day, you can start to buy some books (or at least one), you can start here. Check for great books on amazon.com. This is the link to one great book I am currently reading (C# 2008 Step by Step; there is 2010 version too). On amazon.com you can find many, many books about programming. But the thing is, THERE IS NO FAST WAY of learing programming. It will take time, especially if you dont know any other programming language. If you do, it will be simplier and shorter learning, but in any case you will have to be patient.
btw, there is one great link of the most popular threads on StackOverflow here.

Hope it helps to start with :)

kvprajapati commented: Correct! +14
ddanbe commented: adatapost is right! +14
Mitja Bonca 557 Nearly a Posting Maven

What exactly would you like to do? Can you give us an example?

Mitja Bonca 557 Nearly a Posting Maven

Try this code:

string[] columnData = new string[dataGridView1.Rows.Count];
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                DataGridViewRow row = dataGridView1.Rows[i] as DataGridViewRow;
                columnData[i] = row.Cells["columnName"].Value.ToString();
            }
Mitja Bonca 557 Nearly a Posting Maven

Yes, you have to clear dataSet (or dataTable in case if you dont have dataSet).

Mitja Bonca 557 Nearly a Posting Maven

hi, yes it would be good if you explain this a bit better. I have a few ideas of what do you want, but I will not go and describe all here now.
So..

Mitja Bonca 557 Nearly a Posting Maven

Momerath is saying you cannot multiply some double value with double array value. No go.

You have this code:

double [] perminuterate = { 0.07, 0.10, 0.05, 0.16, 0.24, 0.14 };

What are these numbers mean?
And you have to select ONLY one value from this double array to multiply with user`s input, like:

double [] perminuterate = { 0.07, 0.10, 0.05, 0.16, 0.24, 0.14 };
double userInput = 0M;
double result = 0M;
if(double.TryParse(Console.ReadLine(), out userInput)
{
    //now you have user`s input in correct type, you only habe to select one value from array
    //but which one, this is up to you.
    //example: I will choose 3rd (0.05):
    result = userOutPut * perminuterate[2];
}
Console.WriteLine("Result is {0}.", result.Tostring());
Console.ReadLine();
Mitja Bonca 557 Nearly a Posting Maven

Didnt we show you two example how yucan save the array into *.csv file?
Mine and and sandeepparehk0`s post have these kind of solutions.

Mitja Bonca 557 Nearly a Posting Maven

I would rather suggest you to use generic list<T>. But if you insist uisng string array, you can do it in this way too:

string[] array = new string[7];
//reading port and fill the array!
//then you can do:
string delimiter = ";";
//and write to a file:
string path = @"C\MyFolder\myFile.csv";
System.IO.File.WriteAllText(path, Stirng.Join(delimiter, array));
Mitja Bonca 557 Nearly a Posting Maven

As Momerath said, please tell us what do you want to have in textBoxes, otherwise here is a simple example of a textBoxes array and a loop to insert text into them:

TextBox[] tbs = new TextBox[] {textBox1, textBox2, textBox3 }; //put all of them in here!
//then loop:
for(int i = 0; i < tbs.Lenght; i++)
{
   if(tbs[i] != null) //if needed, if not remove this line!
      tbs[i].Text = "some text + i.ToString();
}
Mitja Bonca 557 Nearly a Posting Maven

Where do you have:

SqlConnection sqlConn = new SqlConnection("connString");

amd for to Read data, you have to opean a connection as well:

sqlConn.Open();

And its good to close it on the end of the code (or use "using" keywords instead).

Mitja Bonca 557 Nearly a Posting Maven

YOu have to set some more parameters, like position (Location), size (if necessary), name, ...:

//inside click event handler
string submitWord = tempWord;
Label lbl = new Label();
lbl.Name ="label1";
lbl.Text = submitword;
lbl.Location = (20, 20); //set your location
lbl.AutoSize = true;
flowLayoutPanel.Controls.Add(lbl);
Mitja Bonca 557 Nearly a Posting Maven

You have to define which value to put into an array. This is happening in 12. row of your code.
Try to change the code into:

Console.WriteLine("enter the limit:");
            int n = int.Parse(Console.ReadLine());
            int[] str = new int[n];
            for (int i = 0; i < n; i++)
            {
                str[i] = i;
            }
            Array.Sort(str);

            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(str[i]+Environment.NewLine);
            }
            Console.ReadLine();