Mitja Bonca 557 Nearly a Posting Maven

Exactly as memorath explained. People are mixing these kind of expressions all the time.

Mitja Bonca 557 Nearly a Posting Maven

And to set max of age to 100 you can do it like:

Private Sub textBox1_KeyPress(sender As Object, e As KeyPressEventArgs)
	'allows backspace key
	If e.KeyChar <> ControlChars.Back Then
		'allows just number keys
		e.Handled = Not Char.IsNumber(e.KeyChar)
		If Not e.Handled Then
			Dim age As Integer
			If Integer.TryParse(textBox1.Text + e.KeyChar.ToString(), age) Then
				e.Handled = If(age < 101, False, True)
			End If
		End If
	End If
End Sub
Mitja Bonca 557 Nearly a Posting Maven

Subscribe to KeyPress event hander of textBox control and use this code inside of it:

Private Sub textBox1_KeyPress(sender As Object, e As KeyPressEventArgs)
	'allows backspace key
	If e.KeyChar <> ControlChars.Back Then
		'allows just number keys
		e.Handled = Not Char.IsNumber(e.KeyChar)
	End If
End Sub
Mitja Bonca 557 Nearly a Posting Maven

like:

Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
	Dim fileName As String = comboBox1.SelectedItem.ToString()
	textBox1.Text = [String].Format("{0}{1}{2}", "C:\files", fileName, ".txt")
End Sub
Mitja Bonca 557 Nearly a Posting Maven

If you have only simple strings as items in comboBOx then you can do:

//in combobox_selectedIndexChanged event:
if(comboBox1.SelectedItem.ToString() == "item 1")
     new Form2().Show();
else if(comboBox1.SelectedItem.ToString() == "item 2")
     new Form3().Show();
else if(comboBox1.SelectedItem.ToString() == "item 3")
     new Form4().Show();
Mitja Bonca 557 Nearly a Posting Maven

To the original post of this thread:
when done with the project, go to upper drop down menu, select Build > Publsh YourApplicationName.
This will create a setup.exr file. You can find it on a specified path.

To the last question: Sorry, we have to follow the forum`s rules, and answer one question at a time per thread. This last question has nothing to do with the thread`s title, so we cannot help you.
Create a new thread and ask the question there. Sorry.

bye

Mitja Bonca 557 Nearly a Posting Maven

I have added a textBox and a button controls on the form. Into textBox you write the number of days in month and press the button:

private void button1_Click(object sender, EventArgs e)
        {
            int noOfDays = int.Parse(textBox1.Text);
            DateTime today = DateTime.Today;
            int tempDays;
            List<string> listOfMonths = new List<string>();
            for (int i = 1; i <= 12; i++)
            {
                tempDays = DateTime.DaysInMonth(today.Year, i);
                if (noOfDays == tempDays)
                    listOfMonths.Add(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(i));
            }
            StringBuilder sb = new StringBuilder();
            foreach (string month in listOfMonths)
                sb.AppendLine(month);
            MessageBox.Show(String.Format("List of months that have {0} days:\n{1}", noOfDays, sb.ToString()));
        }
Mitja Bonca 557 Nearly a Posting Maven

You can use String.Join() method if you data are in stirng array:

string[] arr = { "a", "b", "c" };
string str = String.Join(" ", arr);  //copy str to textBox.Text property

In case if your array is not string array ,you can do it like this:

double[] arrD = { 2.2, 4.5, 6.4 };
 string str2 = String.Join(" ", arrD.Select(s => s.ToString()).ToArray());
Mitja Bonca 557 Nearly a Posting Maven

Just one thing to add here: Why you dont use a FULL parametreized query?
This means that you add parameters for all the values, like you did for StartDate and EndDate.

Mitja Bonca 557 Nearly a Posting Maven

You cannot set DataReader as a binding source to any control. Instead, you should use DataAdapter class.

//...
progress.Value = 40;
OleDbConnection conn = new OleDbConnection("connString");
DataTable table = new DataTable(); //can be a class variable too.
OleDbDataAdapter da = new OleDbDataAdapter("SELECT ID, Status FROM AH01", conn);
da.Fill(table);
GridView1.DataSource = table.DefaultView;
conn.Dispose();
progress.Value = 100;
Mitja Bonca 557 Nearly a Posting Maven

Simple way:

Private Sub button1_Click(sender As Object, e As EventArgs)
	Dim item As String = txtbuttons.text
	Dim tbs As TextBox() = {txtAns, txtAns2, txtAns3, txtAns4, txtAns5}
	For i As Integer = 0 To item.Length - 1
		tbs(i).Text = item(i).ToString()
	Next
End Sub
Pgmer commented: Good one. +6
Mitja Bonca 557 Nearly a Posting Maven

TO ADD:
Now when I read your last post, and if you use while loop this means you have more rows in dataBase. This is now different.
Try using my code, but use WHILE loop instead.

Mitja Bonca 557 Nearly a Posting Maven

Hmm,
try this code, this has got to work:
- if only there are data in database (you say there are)
- if the text in Label2 is same as data read from database

If Mydata.Read() Then
	If DirectCast(Mydata(0), String) = Label2.Text Then
		Button5.Enabled = False
		LinkLabel1.Text = "YOU NEED TO UPDATE!"
			'reader reads, but the string is not the same as in the label2!!
	Else
	End If
Else
	LinkLabel1.Text = ""
End If
Mydata.Close()
Mitja Bonca 557 Nearly a Posting Maven

What do you mean?

Mitja Bonca 557 Nearly a Posting Maven

You cannot have like:

If Mydata(0).Read = Label2.Text Then

This does nothing. Read is a method, and not a property.
SqlDataReader class cannot be compared with some string.
What you can do, is to compare an actual reader with it, like:

If Mydata(0).Read() = Label2.Text Then
	Button5.Enabled = False
	LinkLabel1.Text = "YOU NEED TO UPDATE!"
End If

you can alseo try it in a long way:

If Mydata.HasRows = 0 Then
	Interaction.MsgBox("Could not connect with database. Check firewall and/or try again at a later time.")
Else
	If Mydata().Read() Then
		If DirectCast(MyData(0), String) = Label2.Text Then
			Button5.Enabled = False
			LinkLabel1.Text = "YOU NEED TO UPDATE!"
			Exit
		Else
			LinkLabel1.Text = ""
		End If
	Else
		LinkLabel1.Text = ""
	End If
End If
Mitja Bonca 557 Nearly a Posting Maven

The best approach would be to create a new Thread (or using Backgroundworker - which is almost the same as creating new thread), and put the time consuming code (in your case this is work with database and generating excel file from the data), and put the progressBar on the UI thread. Dont forget to use Delegated to "update" or invoke the control on UI thread to be updated appropriatelly.

Mitja Bonca 557 Nearly a Posting Maven

Try to do this way:

string[] arrString = { "a", "b", "c" };  
List<String> lstString = new List<string>(arrString);

when your method needs to retun a List<T> then you do:

//......
private List<string> GetData()
{
   string[] arrString = { "a", "b", "c" };  
   return new List<string<(arrString);
}
Mitja Bonca 557 Nearly a Posting Maven

Yes, you were right codeorder, I should do it like:

Dim data As String() = comboBox1.SelectedItem.ToString().Split(" "C)
textBox1.Text = data(0)
textBox2.Text = data(1)
Mitja Bonca 557 Nearly a Posting Maven

You didnt say exactly where from, so I will assume from database.
You can write an sql query that will look like:

Dim sqlQuery As String = "SELECT * FROM MyTable WHERE DateColumn >= @param1 AND DateColumn <= @param2"
'by using sqlcommand you then define parameters:
cmd.Parameters.Add("@param1", SqlDbType.DateTime).Value = datetimepicker1.Value
cmd.Parameters.Add("@param2", SqlDbType.DateTime).Value = datetimepicker2.Value
Mitja Bonca 557 Nearly a Posting Maven

simpliest way:

Dim data As String() = comboBox1.SelectedItem.ToString()
textBox1.Text = data(0)
textBox2.Text = data(1)
Mitja Bonca 557 Nearly a Posting Maven

simpliest way to convert stirng to byte[] is:

string str = "some text";
byte[] byteArr = Encoding.UTF8.GetBytes(str);

in your case it seems that you dont have type of byte in the database, but its varchar, so you can only read it to string, like:

string str = (string)cmd.ExecuteScalar();
Mitja Bonca 557 Nearly a Posting Maven

Hi,
check this out:

private void viewSnapShotButton_Click(object sender, EventArgs e)
{
     string connectionString = ConfigurationManager.AppSettings["myCconnectionSstring"];
     string queryString = ConfigurationManager.AppSettings["MyQueryString"];
     SqlConnection connection = new SqlConnection(connectionString);
     try
     {
          connection.Open();
          SqlCommand command = new SqlCommand(queryString, connection);
          byte[] image = (byte[])command.ExecuteScalar();
          MemoryStream ms1 = new MemoryStream(image);
          pictureBox1.Image = Bitmap.FromStream (ms1);  
          ms1.Close();
     }
     finally
     {
          connection.Close();
     }
}
Mitja Bonca 557 Nearly a Posting Maven

So you want to display one one item? If one, which one? If more, you better use Listobx control.

Mitja Bonca 557 Nearly a Posting Maven

A must? Why? This is a nonsense.
All time consuming code must me on seperated thread, otherwise your UI will freeze (like it is now).

Mitja Bonca 557 Nearly a Posting Maven

This code is for email validation. That means that it checks if email is correctly written, so if it is written in correct form only. Method returns true if all ok, and false if email is not in correct form.
You can call this method when ever you want.

Mitja Bonca 557 Nearly a Posting Maven

Hi, check here:

public bool IsValidEmail(string emailAddress)
  {
       if (string.IsNullOrEmpty(emailAddress)) { return false; }

       string _emailPattern = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
       return new Regex(_emailPattern).Match(_emailPattern).Success;
  }
//OR:
private bool ValidatingEmail(string inputEmail)
        {
            string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                  @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                  @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            Regex re = new Regex(strRegex);
            if (re.IsMatch(inputEmail))
                return (true);
            else
                return (false);
        }
Mitja Bonca 557 Nearly a Posting Maven

I guess your problem in in inserting new custome into database.
Your sql query is not ok, chnage it to:

"INSERT INTO Registration (Customer_ID, First_Name, Last_Name, Date_of_Birth, Gender, Phone_Number, Email, Address) VALUES ('"& txtCustomerID.Text &"','" & txtFirstName.Text & "','" & txtLastName.Text & "','" & txtDateOfBirth.Text & "','" & txtGender.Text & "','" & txtPhoneNumber.Text & "', '" & txtEmail.Text & "', '" & txtAddress.Text & "')"

As you can see you have forgot to add double quotes when you define the parameters directly into query statement.

Mitja Bonca 557 Nearly a Posting Maven

Where exactly do you get this error? On which line of code?

Mitja Bonca 557 Nearly a Posting Maven

What are the data type in your Datetgl field (column)? Are an actualy DateTime (date) type?
Or some string? If so, this will not work. It must be an actualy type of DateTime.

Mitja Bonca 557 Nearly a Posting Maven

Exactly. Close() method calls a Dispose() method, which terminates and removes the instance of an object. This means that it does no exist any longer.
To use a Show() method again, you have to create a new instance of an object.

Alternative: Instead of calling Close or Dispose methods, better call Hide() method, which will only hide an object (so it will no be vissible), but when you will call Show() method again, this object will pop up again.

Mitja Bonca 557 Nearly a Posting Maven

This way if you have an integer array (ar any other then string array):

int[] array = { 1, 2, 3, 4, 5 };
MessageBox.Show(String.Join("\n", array.Select(s => s.ToString()).ToArray()));
Mitja Bonca 557 Nearly a Posting Maven

So send a reference into that class. This way will be available here and there. As long as you dont do a NEW referenve it "old" one always has the "old2 data holding inside.

Example:

class Class1
{
     private List<string> list = new List<string>(); //this is now our varaible to use (reference)

     public Class1()
     {
         AddSome();
         ChangeIt();
     }
     void AddSome()
     {
         list.Add("a");
         list.Add("b");
     }
     void ChangeIt()
     {
         Class2 c2 = new Class2(list); //passing list as referece to otrher class
         c2.ChangeList(); //do changes there (ot adding, or...)
         //when code comes back from class2 it will be already changed!!
     }       
}

class Class2
{
    List<string> list;
    public Class2(List<string< _list)
    {
        this.list = _list;
    }
    public void ChangeList()
    {
         list[0] = "aa";
         list[1] = "bb";
    }
}
Mitja Bonca 557 Nearly a Posting Maven

I would go to use >= and <= operators to define the start end end date accordingly:

Dim query As String = "Select * from AFINITY where Description = @description and Datetgl >= @startDate and Datetgl <= endDate"
Mitja Bonca 557 Nearly a Posting Maven

Exactly, all parameters in the insert statment must be seperared by comma.
But you can use a better approach with parametereized query:

cmdtext = "insert into tblSTUDENT(FULLNAME, PARENTNAME, AGE) VALUES(@p1, @p2, @'3)";
cmdtext.Parameters.Add("@p1", SqlDbType.VarChar, 50).Value = txtStudentName.Text;
cmdtext.Parameters.Add("@p2", SqlDbType.VarChar, 50).Value = txtParentName.Text;
cmdtext.Parameters.Add("@p3", SqlDbType.VarChar, 50).Value = txtAgr.Text;

Parameters type must based on the type in your actual databasse. Use VarChar (and its lenght -50 in my example). If you have an integer, change the type to integer, like:

cmdtext.Parameters.Add("@p1", SqlDbType.Int).Value = int.Parse(txtStudentName.Text);

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

You have to subscribe to this event.
It means:

public MainForm()
{
    //button click event subscribtion:
    //if there is no this line of code, event will NOT rise!!
    button1_Click += new EventHandler(button1_Click);
}

//actualy event (it will be rised when button clicked:
private void button1_Click(object sender, EventArgs)
{

}
Mitja Bonca 557 Nearly a Posting Maven

To do the focus and highligh all the text inside ot it:

texrBox1.Focus()
texrBox1.SelectionStart = 0
texrBox1.SelectionLength = textBox1.Text.Lenght
Mitja Bonca 557 Nearly a Posting Maven

try with:

listBox1.Font = New Font("Arial", 10, FontStyle.Regular)
Mitja Bonca 557 Nearly a Posting Maven

Return type can be simply an object.
Then if the other class where you will receive it, you use GetType method:

public class Program
    {
        void YourMethod() //can be main in console!
        {
            object data1 = FETCH(true);
            object data2 = FETCH(false);
            
            //maybe to go through both objects:
            object[] allData = { data1, data2 };
            foreach (object data in allData)
            {
                if (typeof(ROAD) == data.GetType())
                {
                    //is road class
                }
                else if (typeof(PATH) == data.GetType())
                {
                    //is path class
                }
            }
        }

        public object FETCH(bool flag)
        {
            if (flag)
            {
                ROAD obj = new ROAD();
                return obj;
            }
            else
            {
                PATH obj = new PATH();
                return obj;
            }
        }
    }

    public class ROAD
    {
        public string getData()
        {
            return "Marlton Road";
        }
    }

    public class PATH
    {
        public string getData()
        {
            return "Tagore Path";
        }
    }

You can even do it this way, if you wanna check only one object:

object data1 = FETCH(true);
            object data2 = FETCH(false);
                      
            if (typeof(ROAD) == data1.GetType())
            { 
              //is road class
            }
            else if (typeof(PATH) == data2.GetType())
            { 
                //is path class
            }
Mitja Bonca 557 Nearly a Posting Maven

To get items that are selected (the same as all of them), you have to do a loop, and go through them one by one, and do insertion into database.
Example:

SqlConnection conn = new SqlConnection("connString");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = @"INSERT INTO MyTable VALUES (@param1)";
cmd.Parameters.Add("@param1", SqlDbType.VarChar, 50);
for(int i = 0; i < listBox1.SelectedItems.Count; i++)
{
    string item = listBox1.SelectedItems[i].ToString():
    cmd.Parametes["@param1"].Value = item;
    cmd.ExecuteNonQuery();  //each loop a new row will be inseted into DB.
}
cmd.Dispose();
conn.Dispose();
Mitja Bonca 557 Nearly a Posting Maven

Do it this way:

protected void Login_Authenticate(object sender, AuthenticateEventArgs e)
        {
            Boolean blnresult = Authentication("userName", "password"); //provide 2 arguments in here!!!!
            if (blnresult == true)
            {
                e.Authenticated = true;
                Session["Check"] = true;
            }
            else

                e.Authenticated = false;
        }

        protected static Boolean Authentication(string Username, string Password)
        {
            string sqlstring;
            sqlstring = "SELECT userID FROM import_log.dbo.user_verification WHERE userID =" + Username + "";

            System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("Data Source = ietm-fwb-sql1; Initial Catalog = import_log; Persist Security Info = True; User ID = sa; Password = fwbadmin");

            System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sqlstring, con);

            System.Data.SqlClient.SqlDataReader reader;

            con.Open();

            reader = comm.ExecuteReader();

            if (reader.Read())
                return true;
            else
                return false;
        }
    }
}
Mitja Bonca 557 Nearly a Posting Maven

Abstract method cannot have any code implementation.
Only overriden from it.

Mitja Bonca 557 Nearly a Posting Maven

About which password are you talking about?
There can be plenty of them.

Mitja Bonca 557 Nearly a Posting Maven

Sorry, but from your english I cannot get the appropriate question.
Sorry, I cannot help you out with anything yet.

Mitja Bonca 557 Nearly a Posting Maven

Do it this way:

class Program
    {
        static void Main(string[] args)
        {
            Invoice someQuantity = new Invoice("1", "some description", 100, 120);
            Console.Write(someQuantity);
            Console.ReadKey();
        }
    }

    class Invoice
    {
        public Invoice()
        {

        }

        public Invoice(string number)
        {
            this.InvNumber = number;
        }

        public Invoice(string number, string description)
        {
            this.InvNumber = number;
            this.InvDescription = description;
        }

        public Invoice(string number, string description,
                        int price, int purchased)
        {
            this.InvNumber = number;
            this.InvDescription = description;
            this.InvPrice = price;
            this.InvPurchased = purchased;
        }

        public string InvNumber { get; set; }
        public string InvDescription{ get; set; }       
        public int InvPrice{ get; set; }       
        public int InvPurchased{ get; set; }
        public double InvTotalCost
        {
            get { return InvPurchased * InvPrice; }
        }

        public override string ToString()
        {
            return String.Format("Item Description: {0}\nTotal Cost: {1} ", InvDescription, InvTotalCost.ToString("C"));
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Yep, ShowDialog() will make the form to be TopMost all the time when opened.
While Open it only puts the form on top of all when opened, and if you click some other form, this one will be hidden bellow newly clicked form.

Mitja Bonca 557 Nearly a Posting Maven

Simply:

Random r = new Random();
        private void button1_Click(object sender, EventArgs e) //generate numbers by click:
        {
            int total = r.Next(50, 1001);
            List<double> numbers = new List<double>();
            for (int i = 0; i < total; i++)
                numbers.Add(Math.Round(0.0 + r.NextDouble() * 100.0, 2));
            textBox4.Text = String.Join(", ", numbers.Select(s => s.ToString()).ToArray());
        }
Mitja Bonca 557 Nearly a Posting Maven

Maybe the error occures this line:

imgCapture.Image = imgVideo.Image;

if imgVideo is a pictureBox, there is no image inside of this control yet, thats why you get this error.
Try putting this code into OnShow() overriden method.

Just create (write) this event:

protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            //youe code in here
        }

But there can still occur this same error, if there will be on image in the pictureBox.
bye

Mitja Bonca 557 Nearly a Posting Maven

Your program can only rely on the computer time you are using (to the time your computer is set to).
If you really want to get tan actual curent time (your local or some else time), you will have to connect to an internet and get the time from server.
Check here how this can be done.

Mitja Bonca 557 Nearly a Posting Maven

I would suggerst you to get some book for beginners. It will really help you out, because you have to get some basics before going into coding.
A good one for you would be Illustrated C# 2010 (or 2008).

Mitja Bonca 557 Nearly a Posting Maven

I didnt actually get you completely.
Would you like to rise an event when you choose some date?

Please clarify it a bit better.
thx