Newbie Trying to get specific data from an sse database

I am trying to query a specific field from my sse database based on two different variables. And use this information to fill a textbox with an integer.

The first variable is a combobox that is filled with data in one of the other tables in the sse database. This table has a PKcolumn that is an integer and the identity of the column. The only other column is a nvarchar(30) string (which is the actual data in the combobox)

The second variable is a numeric up down that isn't actualy using info from the database but will be a reference. It has a max value written in to the code:

if NumericUpDown1.Value > 20 Then

MessageBox.Show("This form only supports characters up to level 20")

NumericUpDown1.Value = 20

The texbox value will be found in a table that has several columns, the first column is an identity column (also the PK) then it has a column that holds an integer value (the filter criteria for the numeric up down) the next column has the value that will fill the text box, then several other columns that are irrelevant for this, and then the final column is a foreign key that is linked to the primary key of information found in the table that feeds the combo box.

I will post a picture of the database diagram to show all of this information for a better understanding of this post.

I am not looking for someone to write the code for me, but I am totally stumped as to what I need to do, If someone can help me out with this I would greatly appreciate it, thanks in advanced.

http://static.flickr.com/75/154867997_a55d3b0b9e.jpg - this is the table diagram





Answer this question

Newbie Trying to get specific data from an sse database

  • Piquet

    hi,

    this part is not correct

    Class ID =" & ComboBox2.ValueMember

    you suppose to use ComboBox2.SelectedValue

    also for not getting errors if you are sure from the range of the values in numericupdown control in your form load sit the minmum and maxmum

    numericUpDown1.Minimum = 1;

    numericUpDown1.Maximum = 20;

    hope this helps



  • bhowden

    I tried the second option that you presented to me since I do have a dataset. (I really appreciate it)

    here is how I entered it:

    Dim dr() As DataRow = PHDataDataSet.sto_ClassBaseAttack.Select("Class ID =" & ComboBox2.ValueMember & " and ClassLevel = " & NumericUpDown1.Value)

    TextBox1.Text = (dr(0)("BaseAttack1").ToString)

    the only problem is that now I am getting this error:

    SyntaxErrorException was unhandled

    Syntax error: Missing operand after 'ID' operator.

    Unfortunately, I have no idea what this means and can't seem to understand the help that I get on it from MS. Once again, any help would be appreciated.



  • jimh12345

    Ok, I thank everyone for all their help and I think I may take a different approach to this.  I can add the items I want to a combobox and then reference it off of the code later, I just wanted to try to use an sse database, but as I stated before, this is getting over my head rather quickly.  I just purchased a sql server 2005 express edition book, hopefully after reading this I will be more...able to perform the task that I want to do. 

     

     



  • S_Gibson

    hi,

    what's the error messages that you got

    i don't know a specific source but you can try MSDN and also www.CodeProject.com

    hope this helps



  • kaokaokao

    Another thing too, on your Combobox2, you need to change it to :

    Combobox2.SelectedItem.ToString so that it will work in your SQL Select statement.

    Here is a quick and dirty sample on what I mean about things being zero based.

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    With ComboBox1

    .Items.Add("james")

    .Items.Add("was")

    .Items.Add("here")

    End With

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

    Label1.Text = ComboBox1.SelectedItem.ToString + " " + ComboBox1.SelectedIndex.ToString

    End Sub

     

    Put a ComboBox and a label on a form and add the above code. When you select each item in the combobox you will see that even though there are three elements ( james, was, here) in the combobox, the combobox's selected index for "here" is 2. And "james" is 0. Almost all things in Visual Basic are zero based. Unless, you define it otherwise. But, what happens, is , if you don't remember that and change the definitions for every portion of your code, arrays, listboxs, arraylists, and other controls that can have multiple values, you will get errors.  Hope this helps.

    james

    aka:Trucker

     

     

     


  • sajmons

    The problem may be is because Arrays are Zero based and if you are using the values in the Numeric UpDown control and have them set with a minimum of 1 and a maximum of 20 and the array (or even your datatable, which is also zero based, example: 0,0 would get you the first value on the first row in the first column of a data table) this would give you the out of bounds error. Especially on the Maximum setting because the Maximum of 20 would be a greater number than what is in either your array or your data table. If you have an Array or Table with 20 items/rows the count starts at 0 and ends at 19. That gives you 20 rows or elements of an array or table. So, set your Numeric UpDown minumum to 0 and maximum to 19 and see if that doesn't help. You may need to post a bit more of the code you are using where this error occurs if this doesn't help.

    james

    aka:Trucker


  • Roger Luo

    I think you will be better off posting this question in the SQL Server Data Access forum. There are a lot of knowledgable people that post there and can help you with this problem. Hopefully, they can offer you a working idea or solution to your problem.

    james

    aka:Trucker


  • mikelostcause

     

    I do this kind of thing constantly in Knowledge Navigator....

    I do not ever use a database engine to do it for me, I code it on my own and I vey complex queries... there's noting to it.

    This is a complex query where an entire table is iterated

     

    It is driven by data from a row in the table….

     

    The table is arranged hierachically by levels so this query queries by

     

    Level X Parent Name X RecordType

     

    It collects the record numbers of all rows meeting the criteria and outputs them to an arraylist….

     

    Public Function GetTopics(ByRef InputRow As DataRow) As ArrayList

                'GetTopics = New ArrayList

                Dim childlvl As Integer = InputRow.Item _
                                 (DataRecords.ciLevel) + 1

                For Each row As DataRow In CurrentTable.Rows

                    If ((row(DataRecords.ciLevel) = childlvl) And _

                        (row(DataRecords.csParentCategoryName) =
                         InputRow(DataRecords.CsName))) Then

                        If (row(DataRecords.csRecordType) =
                                   RecordType.csTopic) Then

                            If bCaseSensitive Then

                                StoreIt = DirectCast(row
                                (DataRecords.CsName), String).Contains
                                (SearchString)

                            Else

                                StoreIt = (DirectCast(row
                                (DataRecords.CsName), 
                                String
    ).ToLower.Contains(SearchString))

                            End If

                            If StoreIt Then

                                If al.Count = 0 Then al.Add(InputRow _
                                (DataRecords.ciRecordNo))

                                al.Add(row(DataRecords.ciRecordNo))

                            End If

                        End If

                    End If

                Next

                GetTopics = al

     End Function

    Please note this board editor inserts line wraps that really are not there causing what can look like syntax errors

     



  • light.weight

    hi,

    if you have a dataset in  your form, you can creat a dataview dataview contains DataRowView which you can query it like the sql for numbers, strings or even wildcard search it will be something like this

    Dim myDv As New DataView(MyDataSet.Tables("mytableName"), "ColumNameToFilterByitsValue = 'stringvalue' and MyotherColumnNameToFilterByitsValue like '%wildcardfilter%' and MyothercolumNameToFilterByItsValue < intValue", "MyColumnNameThatIuseToSortBy", DataViewRowState.CurrentRows)

    you can loop through each datarowview in the dataview and get the value you want 

     or you can use DataTable.select something like this

    Dim dr() As DataRow MyDataSet.Table1.Select("Column1 = Number and Column2 = 'otherthing'")
    MessageBox.Show(dr(
    0)("Column3").ToString)

    if you don't use dataset then you can write that as sql string and to query it from your database

    hope this helps

     



  • jessica duarte

    I'll try that, thanks

  • kevin ranck

    Good idea on buying the book. Don't give up on your application. I don't know how much programming experience you have, especially with VB and working with SQL Server, but, once you get over a few humps, the learning will be much easier and more fun too!!

    james

    aka:Trucker

    Oh, and don't hesitate to ask questions about anything related to VB. If there are terms that are being used here that you don't understand, ask and someone will try to explain them to you. In fact, on your project, you can always build it little by little. Do the very basic things, like loading the database and displaying what data you may already have in your database. Take it one step at a time, until you feel you are comfortable with what you know and are ready to move on to the next function that you would like to have your program do. If are doing this as a learning experience and not because you have a deadline on a job, then the step by step approach is the best way in my opinion.


  • LEBRUN Thomas

    shakalama wrote:

    hi,

    this part is not correct

    Class ID =" & ComboBox2.ValueMember

    you suppose to use ComboBox2.SelectedValue

    also for not getting errors if you are sure from the range of the values in numericupdown control in your form load sit the minmum and maxmum

    numericUpDown1.Minimum = 1;

    numericUpDown1.Maximum = 20;

    hope this helps

    if I set the numericupdown1 min/max as stated above, it automatically throws the error when I debug the program.

    Also, if I change the combobox2.valuemember to combobox2.selectedvalue then I get a new error.

    What is the best reference for me to look at for this sort of thing



  • Bill Ward

    IndexOutOfRangeException was unhandled

    index was outside of bounds of the array

    ----------------------------------------------------------

    That's the error I got, thanks for the help.



  • guzzy

    And ReneeC, I am very sorry, but that just went pretty far over my head, I thank you for the response though. I am still new, so can anyone give me any references to datasources that will help me out with this

  • Newbie Trying to get specific data from an sse database