Papa_Don 31 Posting Pro in Training

Hi Group!

I suppose this should be titled, "Everything You Wanted to Know about ListViews, but were Afraid to Ask". Here are my questions(s):

I've used ListView with "Details". This has been great when getting smaller bits of information to easily display and edit. However I'd like to use it to display the lines of an "Order Entry" project that I'm working on. Currently the user's entry portion of this covers multiple TextBoxes and 3 "rows" of area. And this is my delima.

Here are my questions:

1) Can ListView be edited/arranged so that I can display all of this user and data table info as a "group" and displayed over multiple rows?
2) What do the other "View" properties of ListView do (i.e. Large Icon, Small Icon, List, Tile)?
3) Would any of these properties work better for what I want to do?

In advance, thanks for you input. I've tried the internet to find these answers. But there isn't enough clarity and there's no way to ask the follow up questions.

I look forward to hearing from you.

Don

Papa_Don 31 Posting Pro in Training

Group,

I'm trying to import an EXCEL table into an SQL Server Table. Although new to SQL, I've done it several times. However for the first time I'm having to import a column that is a date. I'm not sure how the EXCEL column should be formatted so that it can be easily inserted into the sql table. Should the EXCEL column be formated as a 'Date'? If so, in what format ('mm/dd/yyyy', 'yyyy/mm/dd', 'mmddyyyy', 'yyyymmdd', etc.)?

In advance, thanks for all the help.

Don

Papa_Don 31 Posting Pro in Training

Jx_Man,

It should go without say, but I'll say it anyway: I couldn't have found my solution without your help. I greatly appreciate you and tinstaafl stepping up to help. It's one more bit of VB that I've learned!

Thanks,

Don

Papa_Don 31 Posting Pro in Training

tinstaafl,

Never mind. I found a fix. It turned out pretty simple. For the benefit of others, here's what I did:

Private Sub cmbxPrinter_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbxPrinter.SelectedIndexChanged
        Dim sindex As Integer
        Dim sitem As Object
        Dim strsitem As String
        Dim spltitem As String
        If cmbxPrinter.SelectedIndex > -1 Then
            sindex = cmbxPrinter.SelectedIndex
            sitem = cmbxPrinter.SelectedItem
            txbxCustomerNo.Focus()
        End If
        strsitem = Convert.ToString(sitem)
        spltitem = strsitem.Split("|").Last
        printID = spltitem

And, by the way, printID wasn't holding the correct ID as I thought. It was holding the last ID number from the Data Table that was accessed earlier in the module. It just happened that I chose that printer as my test. However with the new code I've written, the correct ID is captured.

Thanks for everyones help!!

Don

Jx_Man commented: Great :) +14
Papa_Don 31 Posting Pro in Training

tinstaafl,

I'm trying to use your suggestion, PrinterId = sitem.Split("|").Last. However I'm getting a "Object reference not set to an instance of an object" error. I'm assuming that it is because 'sitem' is defined as an object and not a string. The overall code for this event is

 Private Sub cmbxPrinter_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbxPrinter.SelectedIndexChanged
        If cmbxPrinter.SelectedIndex > -1 Then
            Dim sindex As Integer
            Dim sitem As Object
            sindex = cmbxPrinter.SelectedIndex
            sitem = cmbxPrinter.SelectedItem
            txbxCustomerNo.Focus()
        End If

        printID = sitem.Split("|").Last

Interesting enough though, I can see that 'printID' is holding the correct ID number. Can you offer a suggestion on how to fix this.

Again, thanks for the help.

Don

Papa_Don 31 Posting Pro in Training

Jx_Man and tinstaafl,

If you saw what convoluted stuff I was writting to parse the printerID out, you'd laugh. However both of your suggestions will work much better than what stuff I wrote. Thanks for these. I may end up using both.

Thanks,

Don

Papa_Don 31 Posting Pro in Training

ddanbe,

In searching further, I did find 'Length', which in reading suggest that it will count the total number of characters in a string. I'm I correct on this?

Thanks for your help. Reading through this helped me make sense of many of these options.

Don

Papa_Don 31 Posting Pro in Training

Group,

I've learned to find the index number of a specific character within a string by writing

dIndex = myText.IndexOf("|")

Obviously, this start counting left to right. But I'd like to do the same but start counting from the right side of the string to the left to find the character. Can this be done in VB?

If not, here's my delima:

I'm using a ComboBox that will house a list of printers to choose from. This will be populated from info in a data table. In the string of information in the ComboBox, I've put a "|" to indicate that the next character(s) will be the PrinterID (key) from the data table. Preceeding this character are multiple spaces so these characters won't be seen when the user uses the ComboBox. Since I don't know if the PrinterID will be '1' or '10' or '100', I've got to parse this number out.

In thinking out loud, if I can find the length of the string (lets call this 'sLength') and then the number of characters to the "|" (dIndex), I can do simple subtraction to find the number of "right" characters.

So, is there a "length" command to find the total number of characters in the string?

In advance, thanks.

Don

Papa_Don 31 Posting Pro in Training

Group,

I found the correct code syntax:

SET TermsPcnt = @tPcnt, TermsDescription = @tDescription, TermsDays = @tDays, TermsProx = @tProx, TermsBillType = @tBillType
WHERE TermsCodeID = @svID
            cmd.Parameters.AddWithValue("@tID", trmID)
            cmd.Parameters.AddWithValue("@tPcnt", termsPcnt)
            cmd.Parameters.AddWithValue("@tDescription", termsDesc)
            cmd.Parameters.AddWithValue("@tDays", tDays)
            cmd.Parameters.AddWithValue("@tProx", sProx)
            cmd.Parameters.AddWithValue("@tBillType", billType)

This is written in Visual Basic.

Hopefully others will find benefit from this.

Thanks, group!

Don

Papa_Don 31 Posting Pro in Training

lolafuertes,

I have no desire to make any changes to the ID field itself. What I want to do is to change the values within that specific ID row. In this specific case I want to edit the fields

LocationNumber, LocationName, LocationAddress1, LocationAddress2, LocationAddress3, LocationCity, LocationState, LocationZipCode, LocationZipCodeExt, PhoneNumber, FaxNumber, BillToAnswer, BillToLocation

Am I asking the wrong question here? Since I want to edit one specific row of the table, is there a "right" way of doing this?

Thanks for you help!

Don

Papa_Don 31 Posting Pro in Training

I'll remember this. Thanks for the suggestion.

Papa_Don 31 Posting Pro in Training

Pritaeas,

I was hoping your suggestions was litteral. However "ALTER permissions for IDENTITY_INSERT" doesn't work. SQL Manager didn't like "permissions". I hate to ask, but what is the correct syntax for writing this? I've not been able to find it.

Thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Group,

I'm trying to write the commands to update a row within a SQL table. I've written the following:

USE DATADESIGNSOLUTIONS
SET IDENTITY_INSERT LocationID ON
INSERT INTO LOCATIONS_SETUP(LocationID, LocationNumber, LocationName, LocationAddress1, LocationAddress2, LocationAddress3, LocationCity, LocationState, LocationZipCode, LocationZipCodeExt, PhoneNumber, FaxNumber, BillToAnswer, BillToLocation)
VALUES(10, 1, 'Traditions in Tile / Buford RDC', '4325 Hamilton Mill Rd', '', '', 'Buford', 'GA', '30518', '', '(770) 831-5324', '(770) 831-6774', 'N', 36)
GO

I'm getting the following error:

"Cannot find the object "LocationID" because it does not exist or you do not have permissions."

I've confirmed the LocationID exists:

LocationID  LocationNumber  LocationName                                LocationAddress1        LocationAddress2    LocationAddress3    LocationCity    LocationState   LocationZipCode LocationZipCodeExt  PhoneNumber         FaxNumber           BillToAnswer    BillToLocation
1           7               Traditions in Tile / Alpharetta Showroom    3065 Trotters Parkway                                           Alpharetta      GA              30004                               (770) 569-1883      (770) 569-9383      N               36
2           36              Traditions in Tile / Corporate              3065 Trotters Parkway                                           Alpharetta      GA              30004                               (770) 569-5232      (770) 569-9383      Y               36
10          1               Traditions in Tile / Buford RDC             4325 Hamilton Mill Rd                                           Buford          GA              30518                               (770) 831-5324      (770) 831-6774      N               36

Am I writing this correctly to allow the edit? If I need "permissions", how is it that I get these?

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

tinstaafl, It worked like it was supposed to. Can you explain to me what made this work? Why didn't my original code work?

Thanks for the help. This is perfect!

Don

Papa_Don 31 Posting Pro in Training

Group,

I'm working to use a second for to do task that will be populate texts boxes in the first form. However I'm getting an error that says, "An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.

In Form1, where the code starts, the code looks like this:

Public Sub cbxEditLocation_Click(sender As Object, e As System.EventArgs) Handles cbxEditLocation.Click
        cbxDeleteLocation.Checked = False
        cbxNewEntry.Checked = False
        cbxEditLocation.Checked = True
        sTask = 1
        Popup_LocationEdit.ShowDialog()
    End Sub

Form2 never opens, but it looks like this:

Private Sub Popup_LocationEdit_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        If sTask = 1 Then
            txbFormType.Text = "Enter the Location to Edit"
        End If
        If sTask = 2 Then
            txbFormType.Text = "Enter the Location to Delete"
        End If
    End Sub

I've tried using "Popup_LocationEdit.Show()" with the same error message. Can someone tell me what's going on here and how to fix it? I know I've done this before. But I don't recall having this kind of error.

Thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Jx_Man,

I've tried your code. It doesn't seem to be doing anything that I was attempting. I wrote it as follows

Private Sub PrinterControl_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        lvPrinterSetup.Width = Me.Width - 40
        Label1.Width = Me.Width - 40
        Label2.Width = Me.Width - 40
        Label3.Width = Me.Width - 40
        Label4.Width = Me.Width - 40
        Label5.Width = Me.Width - 40
        Label6.Width = Me.Width - 40
        Label7.Width = Me.Width - 40
        txbLoc.Width = Me.Width - 40
        txbPrinterAddress.Width = Me.Width - 40
        txbPrinterName.Width = Me.Width - 40
        txbPrinterNo.Width = Me.Width - 40
        txbRow.Width = Me.Width - 40
        btnClearLine.Width = Me.Width - 40
        btnDeleteLine.Width = Me.Width - 40
        btnReturnToMenu.Width = Me.Width - 40
        btnUpdateFile.Width = Me.Width - 40
    End Sub

It appears that the controls (more so the buttons) grew to inside the form when it opened. I've futher discovered that the form couldn't be resized by using the mouse to grab a corner to shrink it (is this a setting in the form's properties?).

Again, thanks for the help. Any other thoughts?

Don

Papa_Don 31 Posting Pro in Training

Jx_Man,

Let me ask, are you saying here that as the user changes the form size, the code you've written will allow everything within the form to change sizes?

I was hoping there was a property setting within the form that would allow this to happen. If there isn't, I don't mind writing some code that will do it. But I do want to ensure the format of the controls within the form will stay in their general location/alignment and will shrink and grow as the form size changes.

As I'm designing my forms, most of these are sized at 1600 X 900 (my screen size). I recognize that other screen sizes will be different. I want to ensure everything will remain proportional as I've designed it. Will the above code do this?

Thanks for your help!

Don

Papa_Don 31 Posting Pro in Training

Hello group!

I've seen one short discussion of ensuring that the controls within a form will shrink, grown and stay in their proportional position as the user changes the form size. Unfortunately it covered parent/child forms, etc. It didn't make a lot of sense to me.

Ultimately I do want the user to see the form as pleasing regardless of the form size. Are there settings in the form properties that will allow the controls, labels, etc., to shrink and grow as the form size changes? Will these controls and labels stay in their relative position as the form size changes? If so, what are the specific settings that I should use?

Thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Rev. Jim,

Thanks. I'm going to play with this a bit and see what and how it can work. I'm trying to think about how the end users will navigate. I know some will use the tab. Some will use the mouse. But it seems that 'Enter' seems to be the most used way to navigate.

Don

Papa_Don 31 Posting Pro in Training

Rev. Jim, I never knew you could shift-tab to go backwards. Thanks for the tip!!

Tinstaafl, I knew that the controls have tab index properties for tabbing. I've used that in every module I've created.

But I've wondered if there was someway I could use the "Enter" key as a tab or the up, down, left and right arrow keys. Can something like that be done?

Thanks guys. I appreciate the help.

Don

Papa_Don 31 Posting Pro in Training

Hi group,

I recognize the today, most people navigate from control to control within a form with their mouse. However some old school people may want to use a "enter" key or a up, down, left or right arrow. I'm curious to know if these kinds of events (if that's the right word to describe the use of these keys) can realistically used in Visual Basic.

As an example, I (or the user) can use the tab key to move from one box to the next. But I have no way of going back one box (or two or three....) except by using the mouse to point and click. What options are available within VB to do such? Is this something that can be set in the properties on the controls? Is this a "keydown" event that I'll need to write code for?

I'm interested in your thoughts and ideas as well as ways to to easily accomplish (if such exists) using these various keys to navigate with.

In advance, thanks for helping this newbie!

Don

Papa_Don 31 Posting Pro in Training

Group,

Call off the dogs..... I've found the answer!

Private Sub lvPrinterSetup_Click(sender As Object, e As System.EventArgs) Handles lvPrinterSetup.Click

        Dim values As New List(Of String)

        If lvPrinterSetup.SelectedItems.Count > 0 Then
            txbRow.Text = lvPrinterSetup.SelectedItems(0).SubItems(0).Text
            txbPrinterName.Text = lvPrinterSetup.SelectedItems(0).SubItems(1).Text
            txbPrinterNo.Text = lvPrinterSetup.SelectedItems(0).SubItems(2).Text
            txbLoc.Text = lvPrinterSetup.SelectedItems(0).SubItems(3).Text
            txbPrinterAddress.Text = lvPrinterSetup.SelectedItems(0).SubItems(4).Text
        End If

    End Sub

It works like a champ!

Papa_Don 31 Posting Pro in Training

Group,

I'm working with a ListView box for the first time. I've figured out how to populate it with data from a database. I now want to click one line of that ListView and have it return each of the five cells from that line into 5 textboxes. I've written the following code that is failing:

Private Sub lvPrinterSetup_Click(sender As Object, e As System.EventArgs) Handles lvPrinterSetup.Click
        Dim values As New List(Of String)
        If lvPrinterSetup.SelectedItems.Count > 0 Then
            For Each item As ListViewItem.ListViewSubItem In lvPrinterSetup.SelectedItems(0).SubItems
                values.Add(item.Text)
                txbRow.Text = Convert.ToString(lvPrinterSetup.SelectedItems(0))
                txbPrinterName.Text = Convert.ToString(lvPrinterSetup.SelectedItems(1))
                txbPrinterName.Text = Convert.ToString(lvPrinterSetup.SelectedItems(2))
                txbPrinterNo.Text = Convert.ToString(lvPrinterSetup.SelectedItems(3))
                txbPrinterAddress.Text = Convert.ToString(lvPrinterSetup.SelectedItems(4))
            Next

        End If
End Sub

This is failing with error notes saying the .SelectedItems(1) "InvalidArgument=Value of '1' is not valid for 'index'. Parameter name: index"

I'm sure that 2 - 4 will fail as well too. Clearly I've written this incorrectly. This is where my lack of programming knowledge and experience is showing up!!

So how do I get these 5 items from one line that I've clicked into the various textboxes?

In advance, thanks for your assistance

Don

Papa_Don 31 Posting Pro in Training

joel.hahn,

I'm going to give this one a try. I'm going to have to read some data from my sql files and use them throughout the program. Having it stored in memory would be a lot more efficient.

Don

Papa_Don 31 Posting Pro in Training

Hazuan Nazri

By the way, the code is working fine now. I have made 1 small addition:

lvPrinterSetup.Items.Clear()

I found as I was making new entries, it wasn't clearing and then adding the new item. Consequently I was getting the same information listed two or three times. This fixed that.

Thanks greatly for the help.

Don

Papa_Don 31 Posting Pro in Training

Begginnerdev,

Yes, all fields are shown. In this particular instance, I needed it to be shown.

I was asking about "ItemColl" because it was originally defined as Dim itemcoll(100) As String. Part of that question also has to do with (100). It's still unclear as to what that does as well. And further, is it needed?

Thanks again,

Don

Papa_Don 31 Posting Pro in Training

GlennT,

I thought that the column number would change. I had forgotten that changing the "Is Identity" would effect that. I did not know to change the "Identity Seed" to effect the starting number.

I doubt that more than one "administrator" will make alterations to this file. But I do not like to take chances.

The only time I'm going to need the Identity ID value is when any changes are to be made. But I've written in for this to happen.

Now that I know all of this, I'm going to dump the idea of creating a ID number and allow the system to take care of this.

Thanks to all for the assistance!

Don

Papa_Don 31 Posting Pro in Training

Begginnerdev, I did define the Listview with "Details" and have already added columns.

AcHillieZ, I've removed

' adding the columns in ListView
        For i = 0 To ds.Tables(0).Columns.Count - 1
            Me.lvPrinterSetup.Columns.Add(ds.Tables(0).Columns(i).ColumnName.ToString())
        Next

Because I've defined these already in the Listview. The only question I have is: what do these lines do?

For j = 0 To ds.Tables(0).Columns.Count - 1
                itemcoll(j) = ds.Tables(0).Rows(i)(j).ToString()
            Next
            Dim lvi As New ListViewItem(itemcoll)

The other part of this is the "itemcoll". What is its purpose? Since I've defined my listview with details and added columns, is this needed?

Thanks for the help. This is working well.

Don

Papa_Don 31 Posting Pro in Training

Begginnerdev,

I've written your suggestion as follows, but I'm still not getting data populating the ListView. Am I missing something?

Dim con As New SqlConnection
    Dim cmd As New SqlCommand

        Dim da As New SqlDataAdapter(cmd)
        Dim ds As New DataSet
        con.ConnectionString = ("Data Source=DON-PC;Initial Catalog=DataDesignSolutions;Integrated Security=True;User ID=DON-PC;Password=be67011;")
        Dim com As New SqlCommand("", con)
        com.CommandText = "SELECT * FROM PRINTERMAINT"
        lvPrinterSetup.Items.Clear()
        con.Open()
        da.Fill(ds, "MyData")
        If IsNothing(ds.Tables("MyData")) = False And ds.Tables("MyData").Rows.Count > 0 Then
            For i = 0 To ds.Tables("MyData").Rows.Count - 1
                With ds.Tables("MyData")
                    Dim lvi As New ListViewItem
                    lvi.Text = .Rows(i)("PrinterID")
                    lvi.SubItems.Add(.Rows(i)("PrinterName"))
                    lvi.SubItems.Add(.Rows(i)("PrinterNumber"))
                    lvi.SubItems.Add(.Rows(i)("PrinterLocation"))
                    lvi.SubItems.Add(.Rows(i)("PrinterAddress"))
                    lvPrinterSetup.Items.Add(lvi)
                End With
            Next
        End If

Any thoughts?

Thanks so much for the help here. This has been a great learning experience.

Don

Papa_Don 31 Posting Pro in Training

GlennT,

I would prefer the auto increment setup within the data table. To do this, is this where I need to open the table in SQL Management and change that specific field to "(Is Identify)" to "Yes"?

Reverend Jim,

At the end of the day, I'd prefer do what is the best way to do it. If "SELECT MAX" is it, I'm all for it. What are the pros and cons?

Don

Papa_Don 31 Posting Pro in Training

Begginnerdev,

Your response prompts a question: Are there advantages or disadvantages to your method? Truthfully, I just want a good, efficient way of handling the information.

With regard to writing and including your actual code suggestion, should it be written like this?

Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Dim da As New SQLDataAdapter(cmd)
        Dim ds As new DataSet

        con.ConnectionString = ("Data Source=DON-PC;Initial Catalog=DataDesignSolutions;Integrated Security=True;User ID=DON-PC;Password=be67011;")
        Dim com As New SqlCommand("", con)
        command.CommandText = "SELECT * FROM PRINTERMAINT"
        lvPrinterSetup.Items.Clear()
        con.Open()

da.Fill(ds,"MyData")
IF IsNothing(ds.Tables("MyData")) = False And ds.Tables("MyData").Rows.Count > 0 Then
    For i = 0 to ds.Tables("MyData").Rows.Count - 1
        With ds.Tables("MyData")
            Dim lvi As New ListViewItem
            lvi.Text = .Rows(i)("PrinterID")
            lvi.SubItems.Add(.Rows(i)("PrinterName"))
            lvi.SubItems.Add(.Rows(i)("PrinterNumber"))
            lvi.SubItems.Add(.Rows(i)("PrinterLocation"))
            lvi.SubItems.Add(.Rows(i)("PrinterAddress"))
            ListView1.Items.Add(lvi)
        End With
    Next
End If  
        rdr.Close()
        con.Close()

Let me know if you think I need to make any changes.

Don

Papa_Don 31 Posting Pro in Training

Hi group,

I've been playing with a ListView and I'm struggling to get it to populated with info in a database. I'm hoping you may see something in my code that is creating the error.

        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Dim rdr As SqlDataReader = cmd.ExecuteReader

        con.ConnectionString = ("Data Source=DON-PC;Initial Catalog=DataDesignSolutions;Integrated Security=True;User ID=DON-PC;Password=be67011;")
        Dim command As New SqlCommand("", con)
        command.CommandText = "SELECT * FROM PRINTERMAINT"
        lvPrinterSetup.Items.Clear()
        con.Open()
        rdr = cmd.ExecuteReader
        Do While rdr.Read()
            lvPrinterSetup.Items.Add(New ListViewItem({rdr(0), rdr(1), rdr(2), rdr(3), rdr(4)}))
        Loop
        rdr.Close()
        con.Close()

To clarify, there are 5 columns in this data table (PRINTERMAINT). They are "PrinterID", "PrinterName", "PrinterNumber", "PrinterLocation" and "PrinterAddress".

Currently, I've attempted to push up at least 3 records. While I've not confirmed they are there, I believe they are.

If you see something that may be creating the failure, please speak up. I'm not getting any kind of error message. I'm just not getting any data to display in the ListView.

Thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Group, it appears that I'm writing to the database. However I'm unable to read the data in the listview I've created. Maybe you can see where my commands are failing. Here's what I'm writing:

con.ConnectionString = ("Data Source=DON-PC;Initial Catalog=DataDesignSolutions;Integrated Security=True;User ID=DON-PC;Password=be67011;")
        Dim command As New SqlCommand("", con)
        command.CommandText = "SELECT * FROM PRINTERMAINT"
        lvPrinterSetup.Items.Clear()
        con.Open()
        rdr = cmd.ExecuteReader
        Do While rdr.Read()
            lvPrinterSetup.Items.Add(New ListViewItem({rdr(0), rdr(1), rdr(2), rdr(3), rdr(4)}))
        Loop
        rdr.Close()
        con.Close()

Can anyone see why my code doesn't seem to be writing to the Listview box?

If you need me, I'll be at the bar shaking and drinking heavily...... (lol!)

Again, thanks greatly for the help. This has been an awesome learning experience.

Don

Papa_Don 31 Posting Pro in Training

For what it's worth, I'm trying to write this now in SQL Server Management 2010 Express. In using the suggestions, I've written it this way"

SELECT TOP 1 *
FROM PRINTERMAINT
ORDER BY 1 DESC

It doesn't like "PRINTERMAINT" (the table name). I am connected to the database, DATADESIGNSOLUTIONS. What in the world is going on here?

Papa_Don 31 Posting Pro in Training

I've written the following line:

cmd.CommandText = "SELECT * FROM PRINTERMAINT ORDER BY PrinterID DESC LIMIT 1"

I'm getting a syntax error that says "Incorrect syntax near 'LIMIT'". It doesn't say what it's looking for. any idea what the correct syntax should be? I'm using Visual Studio (Visual Basic) 2010 Express.

Thanks.

Don

Papa_Don 31 Posting Pro in Training

IIM,

I've been reading through the article you've suggested. One of my (many) issues (from my great lack of experience and knowledge) is that I don't yet understand the query language. Consequently, trying to "translate" this into Visual Basic is somewhat difficult. In this instance, the programmer is "Creat"ing a new table. I'm not doing this. I just want to write to the table this first time. And, for future row creations, I need to find the last row number and add '1' to that.

I do want to try to figure this out. So let me "think" outside here:

The example reads

id MEDIUMINT NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
) ENGINE=MyISAM;

First, I have no idea what "ENGINE=MyISAM" is. Maybe you can explain.

I'm guessing that "id MEDIUMINT NOT NULL AUTO_INCREMENT" is creating the column "id" and that it is a "int" data type (albeit, I've not seen 'mediumint' as a data type). A "NULL" value is not allowed. This field is set to "auto-increment". Finally, "id" has the primary key. How am I doing so far?

Assuming I'm correct here, I still don't know how to use this.

I've purchased a book called "Transact-SQL Programming", by Kevin Klein, Lee Gould and Andrew Zanevsky. I've looked to see if "AUTO_INCREMENT" is covered. It's not. So I'm still at square one.

Now to use your suggestion to find the last row, I gather I should write my commands as this:

        Dim …
Papa_Don 31 Posting Pro in Training

Hi group,

I'm still learning Visual Basic and SQL. Please overlook my inabilities.

I'm writing a module that is meant to write a small amount of data to a database. I've named these fields 'PrinterID', 'PrinterName', 'PrinterNumber', 'PrinterLocation' and 'PrinterAddress'. The user will eventually have 30 or 40 records to add to this file.

My questions are: when writing to the file, how do I number the rows (this will be the PrinterID)? As the user adds to this, how do I find the last row number so that I can assign the next row value? And lastly, do these rows begin with '0' or '1'? I ask, because I assume '0'. But I'd rather it be 1!

In advance, thanks for the help.

Don

Papa_Don 31 Posting Pro in Training

Rev. Jim, You are correct on all counts. This works perfectly! Now I just need to learn how to get it to assign the ID number.

Thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

I must be getting somewhere. I'm getting a new error message now:

"Error converting data type varchar to numeric"

I thought this may be a problem. But I'm not sure how to fix it. Here's the commands to store it:

Dim printID As Integer
    Dim printName As String
    Dim printNo As Integer
    Dim printLoc As Integer
    Dim printadd As String      

        printName = txbPrinterName.Text
        printNo = Convert.ToInt32(txbPrinterNo.Text)
        printLoc = Convert.ToInt32(txbLoc.Text)
        printadd = txbPrinterAddress.Text

Clearly it doesn't like 'printNo' and 'printLoc'. How should I be writing this?

Thanks again. You've got me back on the right track.

Don

Papa_Don 31 Posting Pro in Training

Group,

I've been working for several hours trying to correctly write to a database file. Here are the parameters:

Database Name: DATADESIGNSOLUTIONS
Table Name: PRINTERMAINT
Column Names: PrinterID (primary Key), PrinterName, PrinterNumber, PrinterLocation, PrinterAddress

I've been working at this two ways: through the Visual Basic code and through SQL Server Management. I'm getting the same errors in both places. The error reads:

Invalid column name 'printName'.
Invalid column name 'printNo'.
Invalid column name 'printLoc'.
Invalid column name 'printAdd'.

Here's the code I've written"

Try
                con.ConnectionString = "Data Source=DON-PC;Initial Catalog=DATADESIGNSOLUTIONS;Integrated Security = True;User ID=DON-PC;Password=be67011;"
                con.Open()
                cmd.Connection = con
                cmd.CommandText = "INSERT INTO PRINTERMAINT(PrinterName, PrinterNumber, PrinterLocation, PrinterAddress) " & _
                "VALUES (printName, printNo, printLoc, printAdd)"
                cmd.ExecuteNonQuery()

            Catch ex As Exception
                MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
            Finally
                con.Close()
            End Try

By the way,

INSERT INTO PRINTERMAINT(PrinterName, PrinterNumber, PrinterLocation, PrinterAddress)

doesn't work in SQL Server Management either. It keeps telling me these are invalid column names.

Can someone point out to me what I'm doing wrong?

In advance, thanks for the help.

Don

Papa_Don 31 Posting Pro in Training

Hi group,

Within one form, I need to run a routine twice. Obviously, I can write the code twice in the two places it needs to run. Isn't there a way to write the routine one time and the call it in two places within the form? Would this be a "Function"?

What I need to write is a fairly large datareader routine. Assuming it is a Function, I'm not sure how to write the event correctly. I can use some help.

In advance, thanks.

Don

Papa_Don 31 Posting Pro in Training

Ok.... Thanks. That appears to be working.

Papa_Don 31 Posting Pro in Training

Tinstaafl,

Creating the event as you suggested works. However when I insert the event itself, I get the following message:

"Error 1 'KeyValue' is not a member of 'System.Windows.Forms.KeyPressEventArgs'."

The code looks like this:

Private Sub txbPartNo_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txbPartNo.KeyPress
        If e.KeyValue = Keys.F5 Then
            FuncKeysModule(e.KeyValue)
            e.Handled = True
        End If
    End Sub

Any other suggestions?

Don

Papa_Don 31 Posting Pro in Training

I've gotten an error when trying to do this.

Error 1 Method 'Public Sub txbPartNo_KeyPress1(sender As Object, e As System.Windows.Forms.KeyEventArgs)' cannot handle event 'Public Event KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs)' because they do not have a compatible signature.

I'm thinking I don't clearly understand your instructions.

Don

Papa_Don 31 Posting Pro in Training

Is this what you had in mind?

    Public Sub txbPartNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txbPartNo.KeyPress
        If e.KeyValue = Keys.F5 Then
            FuncKeysModule(e.KeyValue)
            e.Handled = True
        End If

    End Sub

    Public Sub txbDesc_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txbDesc.KeyPress
        If e.KeyValue = Keys.F5 Then
            FuncKeysModule(e.KeyValue)
            e.Handled = True
        End If

    End Sub
Papa_Don 31 Posting Pro in Training

Group,

I need to use Function keys within a form I've created. The problem I'm having is determing the correct routine to fire it off. Here's what I'm attempting to do:

In Form1 (actually called "OrderEntry2"), I want to give the user the option of keying in a part number into the "txbPartNo" textbox. Or, if they don't know the part number, I want to allow them to hit 'F5' to bring up Form2 (called "Popup_PartNo) to find that part number based on the beginning characters that they will enter on that form.

Likewise, should the user not know the beginning characters of the part number, I'd want to give them the option of finding the part number based on a word within the part description. Again I want to allow them to hit 'F5' to bring up Form2 (called "Popup_PartNo) to perform the routine.

My first inclination was to allow the user to give FOCUS to either "txbPartNo" textbox or "txbDescription" textbox to choose which way they want to search. So I wrote the following:

Public Sub txbPartNo_GotFocus(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txbPartNo.GotFocus
        If e.KeyValue = Keys.F5 Then
            FuncKeysModule(e.KeyValue)
            e.Handled = True
        End If

    End Sub

    Public Sub txbDesc_GotFocus(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txbDesc.GotFocus
        If e.KeyValue = Keys.F5 Then
            FuncKeysModule(e.KeyValue)
            e.Handled = True
        End If

    End Sub

    Public Sub FuncKeysModule(ByVal value As Keys)


        'Check what function key is in a pressed state, and then perform the corresponding action.
        Select Case …
Papa_Don 31 Posting Pro in Training

For what it's worth, I'm trying this in Form1:

Public Class OrderEntry2

    Public txbSearchType = New System.Windows.Forms.TextBox()

    Public Sub FuncKeysModule(ByVal value As Keys)


        'Check what function key is in a pressed state, and then perform the corresponding action.
        Select Case value
            Case Keys.F5
                Dim searchtype As Integer
                If txbPartNo.Focused = True Then
                    Popup_PartNumbers.Label1.Text = "Enter the beginning characters of the Part Number to search"
                    searchtype = 1
                    txbSearchType.Text = searchtype
                End If
                If txbDesc.Focused = True Then
                    Popup_PartNumbers.Label1.Text = "Enter a word from the Part Number Description to search"
                    searchtype = 2
                    txbSearchType.Text = searchtype
                End If
                Popup_PartNumbers.ShowDialog()
        End Select

    End Sub

Form2 looks like this:

Public Class Popup_PartNumbers

    Dim searchtype As Integer = Convert.ToInt32(OrderEntry2.txbSearchType)
    Dim con As New SqlConnection("Data Source=Don-PC;Initial Catalog=DataDesignSolutions;Integrated Security = True;User ID=DON-PC;Password=be67011")
    Dim cmd As New SqlCommand("", con)
    Dim search1 As String
    Dim string1 As String

    Private Sub btnFindPart_Click(sender As System.Object, e As System.EventArgs) Handles btnFindPart.Click

        If searchtype = 1 Then
            string1 = txbPart.Text
            search1 = "'" & string1 & "%" & "'"
            cmd.CommandText = "SELECT PartNumber, Description FROM INVENTORY_PRODUCTS where WHERE PartNumber LIKE " & search1
        End If

        If searchtype = 2 Then
            search1 = "'" & "%" & string1 & "%" & "'"
            cmd.CommandText = "SELECT PartNumber, Description FROM INVENTORY_PRODUCTS where WHERE Description LIKE " & search1
        End If

        lvPopup.Items.Clear()
        con.Open()
        Dim rdr As SqlDataReader = cmd.ExecuteReader
        Do While rdr.Read()
            lvPopup.Items.Add(New ListViewItem({rdr(0), rdr(1)}))
        Loop
        rdr.Close()
        con.Close()

I've not been able to get these routines to work as I have 2 …

Papa_Don 31 Posting Pro in Training

Group,

I'm declaring a variable in one form that I need to make available in a second form. My code in Form1 looks like this:

Public Sub FuncKeysModule(ByVal value As Keys)

        Select Case value
            Case Keys.F5
                Dim searchtype As Integer
                If txbPartNo.Focused = True Then
                    Popup_PartNumbers.Label1.Text = "Enter the beginning characters of the Part Number to search"
                    searchtype = 1
                End If
                If txbDesc.Focused = True Then
                    Popup_PartNumbers.Label1.Text = "Enter a word from the Part Number Description to search"
                    searchtype = 2
                End If
                Popup_PartNumbers.ShowDialog()
        End Select

    End Sub

The variable "searchtype" (1 or 2) needs to be read in Form2 to run either one of two routines. How should this be written in Form1 and then how do I read it in Form2.

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Kudo's, Jx_Man! Thanks for this. It's perfect and exactly what I needed.

You're the man!

Papa_Don 31 Posting Pro in Training

Group,

I'm having an issue with SQL Server that has me baffled. I need help.

When I originally loaded SQL Server 2008 Express and created my database, I called it "DataDesignSolutions". The tables were created through VB Studio 2010 Express. It's path was "C:\User\Don\Documents\DataDesignSolutions.mdf". I'm not sure how, but somewhere along the way that path name stuck.

I assumed that was an easy fix. So through SQL Server Manager 2008 Express, I changed the name to "DataDesignSolutions".

Now here's the problem: When testing my program that has a link to this database, it's failing saying the password is incorrect. Assuming the password had somehow been changed, I opened SQL Server manager and find there is a "second" database. The interesting thing is, this "database" is empty. There is absolutely nothing in it. Further, it's name is "DataDesignSolutions". The database that has all the tables is now called "C:\User\Don\Documents\DataDesignSolutions.mdf". Can someone tell me what's going on? How do I fix this?

In advance, thanks for you help.

Don