Mitja Bonca 557 Nearly a Posting Maven

To get data, you have to create a new command, using SELECT statement.

Mitja Bonca 557 Nearly a Posting Maven

You have one main dataTable with all the data. When you want to filter it, create new DataTable, create same column as main one has (by using Clone method):

Dim temp As New DataTable()
temp = mainTable.Clone()
'this was you get the table structure - same as main one

Now use Select property to filter data.
my Example:

Private table As DataTable
Private Sub MethodToFilter()
	table = New DataTable("MainTable")
	table.Columns.Add("Id", GetType(Integer))
	table.Columns.Add("Value", GetType(String))

	'adding some example rows (10):
	For i As Integer = 0 To 9
		table.Rows.Add(i, "item " & i)
	Next

	'now filter:
	'get all rows that Id is higher then 6 (so 3 rows will be added to new dataTable):
	Dim filterDT As DataTable = table.Clone()
	Dim rows As DataRow() = table.[Select]("Id > 6")
	For Each row As DataRow In rows
		filterDT.ImportRow(row)
	Next

	'now use filterDT as your new filtered dataTable...
End Sub
Mitja Bonca 557 Nearly a Posting Maven

To get the path, you have to use treeView2.SelectedNode.FullPath; property.
And its a bit strange to put all the files one beside another into textBox. At lease seperate them, by using some delimiter like commma:

//selected node:
textBox1.Text = ReadFile(treeView2.SelectedNode.FullPath;

//your method
        static string ReadFile(string filePath)
        {
            string ret = "";
            string line;
            StreamReader file = new StreamReader(filePath);
            while ((line = file.ReadLine()) != null)
                ret += line + ", "; //changed to seperate files
            return ret;
        }
Mitja Bonca 557 Nearly a Posting Maven

Compare both texts to "ToLower":

if (text.Contains(arr[x, 0].ToLower()))
{
    text = text.Replace(arr[x, 0], arr[x, 1]);
}
Mitja Bonca 557 Nearly a Posting Maven

One more thing to say, "f1" wil always write out a number with one decimal place.
So if you have a number 12, it will print out 12.0

Mitja Bonca 557 Nearly a Posting Maven

That f1 has nothing to do with alignemnt. Its only meant for numerical values. It actually tell to compiler to round the number; number of decimal places.

For instance, if you have a number 12.3456 and you write "f2", it will round on 2 decimal places, so it will write out 12.34.
It even round up or down:
12.678 -> "f1" -> 12.7

Mitja Bonca 557 Nearly a Posting Maven

hi, check here.

Mitja Bonca 557 Nearly a Posting Maven

Hi, this is called a floating-point number.
check here.

Mitja Bonca 557 Nearly a Posting Maven

Here is my example code (which i did some time ago) and actually used is some where:

Public Shared Function NumberToWords(number As Integer) As String
	If number = 0 Then
		Return "zero"
	End If

	If number < 0 Then
		Return "minus " & NumberToWords(Math.Abs(number))
	End If

	Dim words As String = ""

	If (number \ 1000000) > 0 Then
		words += NumberToWords(number \ 1000000) & " million "
		number = number Mod 1000000
	End If

	If (number \ 1000) > 0 Then
		words += NumberToWords(number \ 1000) & " thousand "
		number = number Mod 1000
	End If

	If (number \ 100) > 0 Then
		words += NumberToWords(number \ 100) & " hundred "
		number = number Mod 100
	End If

	If number > 0 Then
		If words <> "" Then
			words += "and "
		End If

		Dim unitsMap = New () {"zero", "one", "two", "three", "four", "five", _
			"six", "seven", "eight", "nine", "ten", "eleven", _
			"twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", _
			"eighteen", "nineteen"}
		Dim tensMap = New () {"zero", "ten", "twenty", "thirty", "forty", "fifty", _
			"sixty", "seventy", "eighty", "ninety"}

		If number < 20 Then
			words += unitsMap(number)
		Else
			words += tensMap(number \ 10)
			If (number Mod 10) > 0 Then
				words += "-" & unitsMap(number Mod 10)
			End If
		End If
	End If

	Return words
End Function
Mitja Bonca 557 Nearly a Posting Maven

You would like to know whats about this code you pasted in here?
There is actually missing some part - the StandardDie class, but its not so important (mabye for you to understand it is).
Ok,
- 1st you declare 5 new variables of a custom class StandardDie.
- and declate a random class.
- in constructor of a form you instanitate the random variable (so now its ready to be used)
- in form Load event you instantiate 5 new variables of a custom class (and pass an argument of each).
- on a button click you assign to each pictureBox`s (to all 5) property "Image" some parameter - the one from the custom class (cound be an actual image, cant tell you now, because I dont see the actual StandardDie class declaration).

Hope it helps a bit.

Mitja Bonca 557 Nearly a Posting Maven

You mean that only one click on a button is allowed to do the command, if there is more then one click, the message will appear?

Mitja Bonca 557 Nearly a Posting Maven

Sure you can - if its in any help to use 0.0 (maybe for some comparison), but better like this:

private void yourMethod()
{
    float = inputMethod(textBox1.Text);
    if(floaf == 0.0)
    {
         MessageBox.Show("Please enter a number in the account number section "); 
    }
}
public float inputMethod() 
{ 
    float temp; 
    if (!float.TryParse(txtInitialTemp.Text, out temp))    
       return 0.0F;
    else
       return temp;
}
Mitja Bonca 557 Nearly a Posting Maven

Check this out:

bool bExit = false;
            bool bReType = false;
            Console.WriteLine("Please type in a binary number: ");
            while (!bExit)
            {
                while (!bReType)
                {
                    string binarynumber = Convert.ToString(Console.ReadLine());
                    foreach (char digit in binarynumber.ToCharArray())
                    {
                        if (char.IsDigit(digit))
                        {
                            int myInt = int.Parse(digit.ToString());
                            if (myInt != 1 && myInt != 0)
                            {
                                Console.WriteLine("The binary number can only be 1 and 0, please re-type");
                                bReType = true;
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("The char is not a number, please re-type.");
                            bReType = true;
                            break;
                        }
                    }
                    if (!bReType)
                    {
                        bReType = true;
                        bExit = true;
                    }
                }
                bReType = false;
            }
            // when code exits the loop, you can continue working, it will
Mitja Bonca 557 Nearly a Posting Maven

DO:

SqlConnection sqlConn = new SqlConnection("connString");
SqlDataAdapter da = new SqlDataAdapter(@"SELECT * FROM members WHERE name = @param1", sqlConn);
DataTable table = new DataTable();
da.Fill(table);
da.Dispose();
sqlConn.Dispose();
datagridview1.DataSource = DataTable.DefaultView;

thats it.
You will have your data in DataGridView AND Binded. So all changes in datagridview will reflect in dataTable as well.
Only one adevice, set DataTable variable on a class level, like:

namespace yourNameSpace
{
    DataTable table;
    void YourMethod()
    {
        //my code in here
        but for instanitaited a table only do:
        table = new DataTable();
    }
}

Hope it helps, bye

Mitja Bonca 557 Nearly a Posting Maven

Or a bit more suphisitcated, using checking if char is number (and a bit different checking of binary data):

bool bExit = false;
  Console.WriteLine("Please type in a binary number: ");
  string binarynumber = Convert.ToString(Console.ReadLine());
  while (!bExit)
  {
      foreach (char digit in binaryNumber)
      {
          if(char.IsDigit(digit)
          {
              int digit = Convert.ToInt32(new string();
              if (digit != '1' || digit != '0')
              {
                   Console.WriteLine("The binary number can only be 1 and 0, please retype");   
                   bExit = true; //char is not 0 or 1
                   break;
              }
          } 
          else 
               bExit = true; // char is not a number!
      }
      break; // all ok!
   }  
   if(!bExit)
   {
       // when code exits the loop, you can continue working, it will 
   }
Mitja Bonca 557 Nearly a Posting Maven

Hi,
read here about it.

bye

Mitja Bonca 557 Nearly a Posting Maven

This would be the best to use a generic list<T>, where T would be a custom class "AnimalData" for example.
Add data to list (two of them), and then by using Linq get whats missing.

Will it go?

Mitja Bonca 557 Nearly a Posting Maven

Try to read a book, or more of them. Amazon.com is a great place to start with.great place to start with.
And while reading and going through example code, do your own examples in VS.

Mitja Bonca 557 Nearly a Posting Maven

Use Crystal Reports. You can create fields, and pass parameters to them (inside parameters there are your data).
Check this website, and check all the links bellow.

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

What do you mean exactly with "I`m not getting "select Items" on form load event"?

Mitja Bonca 557 Nearly a Posting Maven

Ok, here we go, I`d suggest you to add an aditional row (on top, at index ) to dataTable, like:

'create table and bind it to comboBox:
Dim table As New DataTable()
table.Columns.Add("col1", GetType(String))
table.Rows.Add("item 1")
table.Rows.Add("item 2")
comboBox1.DataSource = table.DefaultView
comboBox1.DisplayMember = "col1"

'now add an item to dataTable:
Dim dr As DataRow = table.NewRow()
dr("col1") = "- Select items -"
table.Rows.InsertAt(dr, 0)
comboBox1.SelectedIndex = 0
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

To mention:
maybe you will find if interesting like I did, I just bought a Kindle (eBook) produced by amazon.com (not sure exactly, but they are selling it at their brand name), which can hold all the books mentioned in *.pdf (or *.doc) format. You can still get them from amazon.com.

Mitja Bonca 557 Nearly a Posting Maven

Plenty of them.
The one gerard just mentioned is one of the greatest, which Iam currently reding.
There are other too:
- Illustrated C# 2008 (great for beginners) (or even 2010 version)
- C# in Depth 2008 (and 2nd Edition)
- C# 2008 (and 2010) Step by Step
- C# 3.0 (and 4.0) Unleashed

-----------

These are one of my favorites, and are teaching basics of OOP, ...
for further learning then depends what do you want to learn more into details (web app, win app, networing, graphics, ...)
Check amazon.com has (almost) all.
Hope it helps.

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

Can you tell us more, please tell us your DB structure.

Mitja Bonca 557 Nearly a Posting Maven

You can do it like this:

Dim dateOfExpiration As DateTime = DateTime.MinValue
Dim sqlConn As SqlConnection = New SqlConnection("connString")
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "SELECT expirationDate FROM MyTable WHERE PhoneName = @name"
cmd.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = "yourPhoneName"
cmd.Connection = sqlConn
sqlConn.Open
Dim reader As SqlDataReader = cmd.ExecuteReader
If read.Read Then
    dateOfExpiration = CType(reader(0),DateTime)
End If
reader.Dispose
cmd.Dispose
sqlConn.Dispose
If (dateOfExpiration.Date > DateTime.Now.Date) Then
    MessageBox.Show("This telephone has expired.")
End If

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

You can do it this way:

Dim date As DateTime = DateTime.Now
If (date.DayOfWeek = DayOfWeek.Monday) Then
    MessageBox.Show("Your name is John.")
ElseIf (date.DayOfWeek = DayOfWeek.Wednesday) Then
    MessageBox.Show("Your name is Tom.")
End If
Mitja Bonca 557 Nearly a Posting Maven

Hi,
hmm, maybe whats wrong here is your select query, it should be like:

cmd.CommandText = @"SELECT date FROM WaynokaLogger WHERE AccountID = '" + newString + "'";

better would be using parametreized query:

cmd.CommandText = @"SELECT date FROM WaynokaLogger WHERE AccountID = @param1";
cmd.Parameters.Add("@param1", SqlDbType.VarChar, 50).Value = newString; //check if this is a varchar (stirng), if not change

Hope it helps,

BTW: as i told you this code must work.

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 set a database field, use a decimal and set 2nd number to number of decimal places:
decimal(18,2) -> 2nd number is a number of numbers behind the decimal delimiter.

NOTE: anyway if you leave all the decimals in the database, this doesnt change anything. When you retreive data back out, you do the rouning, like Momerath showed (by using Math.Round method), or your solution (using N2 in the stirng).

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

I dont know what exactly is this code for, but from your description I can tell you one thing: Amount2 IS NEVER EQUAL TO Amout1.
Thats why it never leaves the while loop.

Double check why those two variables are never equal.

Mitja Bonca 557 Nearly a Posting Maven

As Pgmer asked you, you will have to specify about what index is all about!?

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

In case if you want to get some text, and get it into byte array (or something) and reverse it, then you can try somrtihng like this:

private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length > 0)
            {
                char[] chars = textBox1.Text.ToCharArray();
                Array.Reverse(chars);
                byte[] myBytes = Encoding.UTF32.GetBytes(new string(chars));
                textBox2.Text = Encoding.UTF32.GetString(myBytes, 0, myBytes.Length);
            }
            else
            {
                MessageBox.Show("Deger girilecek alan boş.", "HATA!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Hi,
with all due respect, would you mind telling us the issue of this code?

thx in advance.

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

:)
Simple isnt it?
Im glad you like it.

best regards,
bye

andur92 commented: You are awesome! +1
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

What about this kind of loop:

int temp = 0;
            for (int i = 1; i <= 10; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    Console.Write(++temp);
                }
                Console.WriteLine();
            }
            Console.ReadLine();
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

Are these data which are shown in DGV binded from some data source, like dataTable?

Mitja Bonca 557 Nearly a Posting Maven

If I understand you, you want to get 20 different numbers (or what ever) using a Random class. If you will only use random.Next method, it possible of duplications too you know.
Ok, next thing, you have to show all 20 numbers in the order they were inserted into an array, and the same 20 numbers sorted.

So lets do this code:

Random r = new Random();
int[] array = new int[20];
for(int i = 0; i < array.Lenght; i++)
{
    while(true)
    {
         int num = r.Next(1, 10001);
         if(!array.Contains(num)
         {
              array[i] = num;
              break;
         }
    }
}
Console.WriteLine("Unsorted numbers are: {0}.", String.Join(",", array.Select(s => s.ToString()).ToArray()));
Array.Sort(array); //sorting array!
Console.WriteLine("Sorted numbers are: {0}.", String.Join(",", array.Select(s => s.ToString()).ToArray()));

Last part is using Linq, to display an array, using Join method. Inside of it I used a Linq (lambda expressions) to join numbers, which must be strings it you want to use Join method).

Not big deal.

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?