Mitja Bonca 557 Nearly a Posting Maven

Tital i double type, so convert the value from dataRow to double (use Convert ot parse method).

Mitja Bonca 557 Nearly a Posting Maven

Try using:

Dim conn As New SqlConnection("connString")
Dim query As String = "SELECT * FROM products"
Dim cmd As New SqlCommand(query, conn)
Dim da As SqlDataAdapter = New SqlDataAdaper(cmd)
Dim table As New DataTable("myTable")
da.Fill(table)
'dispose all IDisposable objects...
Mitja Bonca 557 Nearly a Posting Maven

codeorder: How on earth can you multiply strings together (or any other math operations)? Never seen thi before...

Mitja Bonca 557 Nearly a Posting Maven

Do:

Double.Parse(txtHoursWorked.Text) * Double.Parse(delstHourlyRate.SelectedItem) + Double.Parse(txtHoursOvertime.Text) * DoubleRate
Mitja Bonca 557 Nearly a Posting Maven

You are a BAD reader mate.
If you would read my post in some other tread of yours, you would see I told you you can NOT do mathematical opearations over stirngs.
Text property or textbox, SelectedItem of listBox, are type of string, and thats why you cannot do math operations over them - I repeat.

You are ONLY allowed to do math operations over real number types, like integer, decimal, double, float, uint, ulong.

So what to do? You already have examples that we gave you. Convert or Parse to particulat type.

Mitja Bonca 557 Nearly a Posting Maven

Please try using break point, and go through the code line by line, and you will find out where exactly the problem is.
I told you maybe I didnt set the correct value, I used Integer for some of them, maybe you have some other type. Check them out!!!

Mitja Bonca 557 Nearly a Posting Maven

Remember:
1. you cannot do math operations over strings; you MUST convert them to appropriate type (I used integers, if trey are not, change them to appropriate type!!
2. messagebox shows strings, so if there is any value not-a-string, convert (or parse) it to stirng.
So do:

MessageBox.Show("Basic hours worked: " + txtHoursWorked.Text & vbCr & vbLf & 
"Hourly rate of pay: " & lstHourlyRate.SelectedItem.ToString() & vbCr & vbLf & 
"Basic pay: " & (Integer.Parse(txtHoursWorked.Text) * Integer.Parse(lstHourlyRate.SelectedItem.ToString())) & vbCr & vbLf & 
"Overtime hourly rate: " & DoubleRate & vbCr & vbLf & 
"Overtime pay: " & OvertimePay & vbCr & vbLf & 
"Total pay: " & (Integer.Parse(txtHoursWorked.Text) * Integer.Parse(lstHourlyRate.SelectedItem.ToString())))

If "vbCr & vbLf" dones not do, try using "Environment.NewLine"
Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

You have to use StringBuilder class to write into it 1st, then when you are done with reading files, you do the Write thing.
So your code shoud look (in sepearate methods):

class Program
    {
        static void Main(string[] args)
        {
            string readFrom = @"F:\abc\";
            string writeTo = @"F:\test.txt";
            StringBuilder sb = Read(readFrom);
            Write(writeTo, sb);
        }

        private static StringBuilder Read(string filePath)
        {
            StringBuilder sb = new StringBuilder();
            DirectoryInfo di = new DirectoryInfo(filePath);
            FileInfo[] files = di.GetFiles("*.txt");
            foreach (FileInfo fri in files)
            {
                using (StreamReader streamReader = fri.OpenText())
                {
                    string line;
                    for (int count = 0; count < 10; count++)
                    {
                        line = streamReader.ReadLine();
                        string[] items = line.Split(' ');
                        float myInteger = float.Parse(items[1]);
                        sb.AppendLine(myInteger.ToString()); //this will write line byline (you can use Append() method only to write in a single line
                        //but you will neeed separator then (I think)
                    }
                }
            }
            return sb;
        }

        private static void Write(string filePath, StringBuilder sb)
        {
            using (StreamWriter file = new StreamWriter(filePath, true))
            {
                file.WriteLine(sb.ToString());
                file.Close();
            }
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Please write some notes on the lines where errors are.

Mitja Bonca 557 Nearly a Posting Maven

try:

If listBox2.Items.Contains(listBox1.SelectedItem.ToString) Then
    MessageBox.Show("This item is in listbox 2.")
End If
Mitja Bonca 557 Nearly a Posting Maven

Otherwise you can do parameterised query:

sql1 = "update po_detail set po_number= @param1 where po_number=0;"
        cnn1 = New OleDbConnection(connectionString)
        cnn1.Open()
        cmd1 = New OleDbCommand(sql1, cnn1)
        cmd1.Parameters.Add("@param1", OleDbType.Int).Value = Integer.Parse(txtPoNo.Text) ' NOTE: CHECK THE TYPE OF YOUR COLUMN IN DB!!!
        cmd1.ExecuteNonQuery()
Mitja Bonca 557 Nearly a Posting Maven

try like:

"update po_detail set po_number= '" & txtPoNo.Text & "' where po_number = 0"

or if your database column is type of integer:

"update po_detail set po_number= '" & Integer.Parse(txtPoNo.Text) & "' where po_number = 0"
Mitja Bonca 557 Nearly a Posting Maven

Based on my previous code:

....
For Each row As DataRow In rows
	table.ImportRow(row)
Next
'pass the data from table to textboxes:
textBoxName.Text = tableNew.Rows(0)(0)
' 1st zero is row index, 2nd zero is column index - 1st row and 1st column
'for other do the same...
Mitja Bonca 557 Nearly a Posting Maven

You would like to get only the rows of customers that have the written lastname in textBox, if I got you right?

This means you have to do the filtering over dataSet to get new DataRows (array of them) and them convert this array back to dataset to bind it again with datagridview.
This can be done like this.

Dim ds As DataSet
'** means:
'check for correct name of the table in dataset, you can still use index like [0] if this is 1st or only table in dataset

    
    'class variable where you have all the data of customers and its bind to datagridview
    Private Sub DoTheFiltering()
        Dim filter As String = txtCustSearchNewBooking.Text
        Dim query As String = "LastName like '%" & filter & "'"
        Dim rows() As DataRow = ds.Tables("Customers").Select(query)
        '**
        Dim tableNew As DataTable = New DataTable("SelectedCustomers")
        'create columns for table:
        For Each column As DataColumn In ds.Tables("Customers").Columns
            tableNew.Columns.Add(New DataColumn(column.ColumnName, GetType(System.String)))
        Next
        'adding rows to table:
        For Each row As DataRow In rows
            table.ImportRow(row)
        Next
        'bind new datasource to dgv:
        dataGridView.DataSource = Nothing
        'resetting datasource
        dataGridView.DataSource = ne
        BindingSource(tableNew, Nothing)
    End Sub

This should do it.

Mitja Bonca 557 Nearly a Posting Maven

If so, here`s an exampe:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs)
	Dim filePath As String = "C:\Myfile.txt"
	'use your path!
	If Not File.Exists(filePath) Then
		Dim fs As FileStream = File.Create(filePath)
		fs.Close()
	End If
	Using fs As New FileStream(filePath, FileMode.CreateNew, FileAccess.Write)
		Using sw As New StreamWriter(fs)
			For Each item As String In listBox1.Items
				sw.WriteLine(item)
			Next
		End Using
	End Using
End Sub
Mitja Bonca 557 Nearly a Posting Maven

I have a listbox and would like to save the items...

Save them where? To a database, to excel, to text file,..?

Mitja Bonca 557 Nearly a Posting Maven

Good question Momerath, but I doubt, otherwise, he wouldnt ask us. Its quite some code, if you want it to make it up for you.
Tell us what you know already, so you make it easier for us.

Mitja Bonca 557 Nearly a Posting Maven

OR:
You'll have to add support to the ListView class so you can be notified about scroll events. Add a new class to your project and paste the code below. Compile. Drop the new listview control from the top of the toolbox onto your form. Implement a handler for the new Scroll event.

Imports System.Windows.Forms

Class MyListView
	Inherits ListView
	Public Event Scroll As ScrollEventHandler
	Protected Overridable Sub OnScroll(e As ScrollEventArgs)
		Dim handler As ScrollEventHandler = Me.Scroll
		RaiseEvent handler(Me, e)
	End Sub
	Protected Overrides Sub WndProc(ByRef m As Message)
		MyBase.WndProc(m)
		If m.Msg = &H115 Then
			' Trap WM_VSCROLL
			OnScroll(New ScrollEventArgs(CType(m.WParam.ToInt32() And &Hffff, ScrollEventType), 0))
		End If
	End Sub
End Class

Beware that the scroll position (ScrollEventArgs.NewValue) isn't meaningful, it depends on the number of items in the ListView. I forced it to 0. Following your requirements, you want to watch for the ScrollEventType.EndScroll notification to know when the user stopped scrolling. Anything else helps you detect that the user started scrolling. For example:

Private mLastScroll As ScrollEventType = ScrollEventType.EndScroll

Private Sub myListView1_Scroll(sender As Object, e As ScrollEventArgs)
	If e.Type = ScrollEventType.EndScroll Then
		scrollEnded()
	ElseIf mLastScroll <> ScrollEventType.EndScroll Then
		scrollStarted()
	End If
	mLastScroll = e.Type
End Sub
Mitja Bonca 557 Nearly a Posting Maven

Add a new class into your project and paste this code:

Imports System.Windows.Forms

Public Class BetterListBox
	Inherits ListBox
	' Event declaration
	Public Delegate Sub BetterListBoxScrollDelegate(Sender As Object, e As BetterListBoxScrollArgs)
	Public Event Scroll As BetterListBoxScrollDelegate
	' WM_VSCROLL message constants
	Private Const WM_VSCROLL As Integer = &H115
	Private Const SB_THUMBTRACK As Integer = 5
	Private Const SB_ENDSCROLL As Integer = 8

	Protected Overrides Sub WndProc(ByRef m As Message)
		' Trap the WM_VSCROLL message to generate the Scroll event
		MyBase.WndProc(m)
		If m.Msg = WM_VSCROLL Then
			Dim nfy As Integer = m.WParam.ToInt32() And &Hffff
			If Scroll IsNot Nothing AndAlso (nfy = SB_THUMBTRACK OrElse nfy = SB_ENDSCROLL) Then
				RaiseEvent Scroll(Me, New BetterListBoxScrollArgs(Me.TopIndex, nfy = SB_THUMBTRACK))
			End If
		End If
	End Sub
	Public Class BetterListBoxScrollArgs
		' Scroll event argument
		Private mTop As Integer
		Private mTracking As Boolean
		Public Sub New(top As Integer, tracking As Boolean)
			mTop = top
			mTracking = tracking
		End Sub
		Public ReadOnly Property Top() As Integer
			Get
				Return mTop
			End Get
		End Property
		Public ReadOnly Property Tracking() As Boolean
			Get
				Return mTracking
			End Get
		End Property
	End Class
End Class

Build your project, then drop a BetterListBox from the top of your toolbox onto your form. Add several items, enough to get a scrollbar. Write a handler for the new Scroll event, something like this:

Private Sub betterListBox1_Scroll(Sender As Object, e As BetterListBox.BetterListBoxScrollArgs)
	Console.WriteLine("Scroll to {0}, tracking={1}", e.Top, e.Tracking)
End Sub

The e.Top property tells you which item is now displayed at the top of the ListBox. e.Tracking is true …

Mitja Bonca 557 Nearly a Posting Maven

Did you set the column to be type of Image in the 1st place?

Mitja Bonca 557 Nearly a Posting Maven

You mean, user MUST enter something?
Something like this?

string input = "";
            while (input.Length == 0)
            {
                input = Console.ReadLine();
                if (input.Length == 0)
                    Console.WriteLine("Please enter some text...");
            }
            Console.WriteLine("This is users input: {0}.", input);
Mitja Bonca 557 Nearly a Posting Maven

Why not using some while(true) loop?
Then then you want to exit, just do "break;".

Mitja Bonca 557 Nearly a Posting Maven

Can you show us ur code? The part thats bothering you.
Iam defenatelly sure there is NO need to use switch inside another switch statements. I did more complicated codes, and so far never did something like you :)

Mitja Bonca 557 Nearly a Posting Maven

Hmm, we would need a BETTER explanation of the problem here. Why would you use switch inside a switch?
Makes no sence to me...yet!

Mitja Bonca 557 Nearly a Posting Maven

I cant open the file. Can you create an image? Print screen, cut the image (with photoshoop or something) and paste it here (or on some free server), and paste link here.

Mitja Bonca 557 Nearly a Posting Maven

Update into??
This is no sql query.
OR: SELECT a from table
OR: INSERT INTO table VALUES(valueA, ..)
OR: UPDATE table SET valueA = @param1,...

So whats it gonna be?

If you mean to do an UPDATE you do:

string query = @"Update Sparepartslist SET ColumnName2 = @param1 WHERE ColumnName1 = @param2"; //NO WHITE SPACES, like you did!!!
//AND WHERE clause SI NEEDED so the code knows which row to update!! usually its an ID column, or some uniqe name!
com = new SqlCommand(query, dbCon);
com.Parameters.Add("@param2", SqlDbType.Int).Value = "your unique value, like ID";
com.Parameters.Add("@param1", SqlDbType.Int).Value = "your value to update"; //chnage tge Type to what the column really is a type of!
com.ExecuteNonQuery();
Mitja Bonca 557 Nearly a Posting Maven

Use breakpoints, and tell us where exactly error occurs.

Mitja Bonca 557 Nearly a Posting Maven

Try to bind data. I mean, fill dataTable and bind it to dgv:

//retreive data from db to datatable:
            SqlDataAdapter adpat = new SqlDataAdapter();
            adpat.SelectCommand = new SqlCommand("select * from ImgTB", con);
            DataTable table = new DataTable("myTable");
            adpat.Fill(table);
            
            //create image column: 
            DataGridViewImageColumn photoColumn = new DataGridViewImageColumn();
            photoColumn.DataPropertyName = "Picture";
            photoColumn.Width = 200;
            photoColumn.HeaderText = "Picture column";
            photoColumn.ReadOnly = true;
            photoColumn.ImageLayout = DataGridViewImageCellLayout.Normal;
            dataGridView1.Columns.Add(photoColumn);           
            //bind data to dgv:
            dataGridView1.DataSource = new BindingSource(table, null);
Mitja Bonca 557 Nearly a Posting Maven

And you had t vote -1? Thx, I really appreciate it. I missed one sinlge quotation mark.
It should be:

Dim myqry As String = "UPDATE tblReceive SET "
myqry += "ProductName = '" + txtProd.Text & "', "
myqry += "Quantity= '" + txtQuan.Text & "', "
myqry += "Quantity Unit= '" + ComboBox3.SelectedItem & "', "
myqry += "Category = '" + ComboBox2.SelectedItem & "', "
myqry += "Supplier = '" + ComboBox1.SelectedItem & "', "
myqry += "ReceivedDate = '" + txtDate.Text & "', "
myqry += "ReceivedBy = '" + ComboBox4.SelectedItem & "' "
myqry += "WHERE "
myqry += "ProductID = '" + txtID.Text & "'"

Happy now?

ANd thx ones again for voting -1.

BTW: what is your point in showing this table? The table structure has nothing to do with this code. I could vote -1 for you too, but Iam not such an ass. Iam trying to help here for a difference from some of you here.

Mitja Bonca 557 Nearly a Posting Maven

You had some error, this should work now:

Dim myqry As String = "UPDATE tblReceive SET "
myqry += "ProductName = '" + txtProd.Text & "', "
myqry += "Quantity= " + txtQuan.Text & "', "
myqry += "Quantity Unit= '" + ComboBox3.SelectedItem & "', "
myqry += "Category = '" + ComboBox2.SelectedItem & "', "
myqry += "Supplier = '" + ComboBox1.SelectedItem & "', "
myqry += "ReceivedDate = '" + txtDate.Text & "', "
myqry += "ReceivedBy = '" + ComboBox4.SelectedItem & "' "
myqry += "WHERE "
myqry += "ProductID = '" + txtID.Text & "'"
kingsonprisonic commented: error Solution : myqry += "Quantity= " + txtQuan.Text & "', " -1
ja928 commented: Good effort to help improve someone else's vague post +1
Mitja Bonca 557 Nearly a Posting Maven

Crystal Reports are not included in VS 2010. You have to install them by your self, and you an get them from SAP.
Last version of VS that had Crystal Reports was previous one, 2008.

Mitja Bonca 557 Nearly a Posting Maven

Why use private fileds, if they are only visible from that class? Its pointless.

If you will use properties (like I did), they look like:

private string name;
public stirng Name
{
    get { return name; }
    set { name = value; }
}

in this say you can only acces to Name (public part of property), and not to name!
But I dont think you will use properties - and use them as private is pointless.
They can only be accessible from INSIDE this class.

So can I ask you who give you this task? Because its a bit strange (at least what you are trying to do).

ddanbe commented: Well explained +15
Mitja Bonca 557 Nearly a Posting Maven

You are a bit off in this case RFID. If you want to learn array, dont use these kind od examples, there are way better ways to get the data from persons.

The simpliest way would be:

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hi, please insert data for 5 people. Follow the instructions. thx.");
            Person[] ppl = new Person[5];
            for (int i = 0; i < ppl.Length; i++)
            {
                ppl[i] = new Person();
                Console.WriteLine("For " + (i + 1).ToString() + ". person type:");
                Console.Write("Name: ");
                ppl[i].Name = Console.ReadLine();
                Console.Write("Telephone: ");
                ppl[i].Telephone = Console.ReadLine();
                Console.Write("Heigh: ");
                ppl[i].Height = int.Parse(Console.ReadLine()); //be careful, if you will type a string, an exception will be thrown
            }
            Console.WriteLine("Thx for filling the data.");
            Console.ReadLine();
        }
    }

    class Person
    {
        public string Name { get; set; }
        public string Telephone { get; set; }
        public int Height { get; set; }
    }
Mitja Bonca 557 Nearly a Posting Maven

1. are you sure you did select an item in comboBox?
2. about sql where clause: are you sure label3.Text property holds same column name as its in the dataBase?
2.1 and if the searchTbx.Text property holds the name that exists in that column?

If any of these 3 questions will be answered as negative, your dataset will be empty (and so will be gridview)!!

Otherwise code look clean - no errors found.
Check the code step by step and slowely - you might find any glitch.

Mitja Bonca 557 Nearly a Posting Maven

Where do you want to store the read rows from database? And why? This sounds a bit strange.

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

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

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

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

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

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

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

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

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

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

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.