john.knapp 25 Posting Whiz in Training

Ok, that works - self-solved still counts as a solved thread :)

john.knapp 25 Posting Whiz in Training

If you step through the code, what is the value of e.Index on Rows 58 & 59?

You should use a loop for that incremental count too. You'd have to put the textboxes into an array in the order you want them filled in, then just loop 0 to 59.

Something like:

Dim myTextBoxes() As string = {frmImpound.lblRev.Text, _
                                frmImpound.txt_agency_case_number.Text, _
                                frmImpound.txtImpoundNumber}

For i As Integer = 0 To UBound(myTextBoxes)
    While i < DataGridView1.Rows.Count
        myTextBoxes(i).Text = DataGridView1.Item(i, e.RowIndex).Value.ToString
        If i = 52 AndAlso DataGridView1.Item(i, e.RowIndex).Value.ToString = "1" _
                                            Then frmImpound.cbOther2.Checked = True
        ' debug line here, to see where we're at with that index issue
        If i = 58 
            Debug.Print DataGridView1.Rows.Count
            Debug.Print e.RowIndex
        End If
    End While
Next
RobRTaylor commented: Awesome, thanks +0
john.knapp 25 Posting Whiz in Training

Definitely the query string. I didn't rewrite the whole project though... :)

TnTinMN commented: if they would just read what we post. +0
john.knapp 25 Posting Whiz in Training

Don't you need to add the row after setting the values?

john.knapp 25 Posting Whiz in Training

What method did you use to databind the combobox?

john.knapp 25 Posting Whiz in Training

No problem, don't forget to mark thread as solved if/when you're done

john.knapp 25 Posting Whiz in Training

Never mind, found a copy of your DB in the bin folder.

john.knapp 25 Posting Whiz in Training

I have downloaded the project source - but I'll need the database as well, or at least the table structure

john.knapp 25 Posting Whiz in Training

FWIW, the key/value pairs are shown as a byte[] array in a SQL Trace... :\

john.knapp 25 Posting Whiz in Training

I am unable to find any documentation stating UID or PWD are valid Key/Value pairs (attributes) in SQLConfigDataSource().

I can change my attributes to use TRUSTED_CONNECTION=NO and as long as I do not pass the UID & PWD pairs - I still get the ODBCAD32 dialog. As soon as I try to pass those pairs, the connection returns an error.

My best suggestion is to use Windows Authentication, or use the ODBCAD32 dialog to input the UserID and Password for the connection (That does work!)

john.knapp 25 Posting Whiz in Training

Thanks - but... I can't take that prop, the OP found it, I'm just trying to get the SQL Auth to work - Windows Security works like a champ, but not so much with SQL Security

john.knapp 25 Posting Whiz in Training

Correction! Code above is for a Trusted Connection - using Windows Security, having difficulty myself with SQL security

john.knapp 25 Posting Whiz in Training

If you're using SQLExpress you have to specify that as part of the SQL instance name.
For example: "Server = WH306UT\SQLExpress"

I just ran a test using your code, but specifying my machine and SQL instance successfully.

See code below, change server and instance name to match your system (of course!):

Private Sub CreateDSN()

    ' NOTE: This procedure creates a User DSN, **NOT** a System DSN
    '
    Dim strDriver As String
    Dim strAttributes As String
    strDriver = "SQL Server"
    Dim catalog As String = "Hospital_DSN"
    '
    ' NOTE THE INSTANCE NAME
    strAttributes = "SERVER=WH306UT\SQLExpress" & Chr(0)
    'strAttributes = "SERVER=" & machName & "" & Chr(0)
    '
    ' THESE ARE YOUR CONNECTION ATTRIBUTES BELOW
    strAttributes = strAttributes & "DSN=" & catalog & Chr(0)
    strAttributes = strAttributes & "DESCRIPTION=DSN For HOSPITAL" & Chr(0)
    strAttributes = strAttributes & "DATABASE=TEST_DB" & Chr(0)
    strAttributes = strAttributes & "TRUSTED_CONNECTION=YES" & Chr(0)

    ' IF YOU WANT TO SEE THE ODBCAD32.exe DIALOG 
    ' PASS THE WINDOW HANDLE OF THIS FORM AS THE FIRST ARGUMENT
    ' EX: SQLConfigDataSourceW(Me.Handle, 1, "SQL Server", strAttributes)
    '
    Dim iReturn As Integer = PInvokeImports.SQLConfigDataSourceW(CType(0, IntPtr), _
                                                    1, "SQL Server", strAttributes)
    If CBool(iReturn) Then
        MsgBox("DSN setup complete successfully.", _
                CType(MsgBoxStyle.OkOnly + MsgBoxStyle.Information, MsgBoxStyle))
    Else
        MsgBox("DSN setup can not complete successfully.")
    End If
End Sub

PInvokeImports Class (in a separate code file):

Imports System.Runtime.InteropServices

Public Class PInvokeImports
    'Const ODBC_ADD_DSN = 1           ' Add data source
    'Const ODBC_CONFIG_DSN = 2        ' Configure (edit) data source
    'Const ODBC_REMOVE_DSN = 3        ' Remove data source …
TnTinMN commented: Nice Job finding and using the function +5
john.knapp 25 Posting Whiz in Training

You're using a DLLImport statement to reference the WinAPI call for SQLConfigDataSource(), right? Can you post your Platform Invoke statement please? It should be something like:

Note: untested code, copied from PInvoke.net

Imports System.Runtime.InteropServices

Class NativeMethods
    <DllImport("ODBCCP32.dll", CallingConvention:=CallingConvention.Winapi, _
                            CharSet:=CharSet.Unicode, SetLastError:=True)> _
    Public Shared Function SQLConfigDataSourceW(ByVal hwndParent As Integer, _
                                                ByVal fRequest As Integer, _
                                                ByVal lpszDriver As String, _
                                                ByVal lpszAttributes As String) _
                                                As Integer
    End Function
End Class
john.knapp 25 Posting Whiz in Training

Can you zip up your project folder and upload it to Rapidshare?
Clean the solution first, please. Post the link at Rapidshare once you have it uploaded.

john.knapp 25 Posting Whiz in Training

Line 6, 13, and 27, by replacing the FormNo by Address

Where does Address come from? It is not in your original query

john.knapp 25 Posting Whiz in Training

Please confirm the exact line of code where the exception occurs.

why is it if im using the address as valuemember and selectedvalue, it runs correctly?

Good question. I do not know, as I do not see [address] in your original DataAdapter CommandText. Where does [address] come into play?

Can you execute this query directly? (From Server Explorer, right-click database ->refresh, right-click database -> new query)
SELECT * FROM tbleMember WHERE FormNo = REPLACE_THIS_TEXT_WITH_A_VALID_VALUE

no value given for parameters

This implies a parameterized query (as I stated before) OR a filter parameter on a dataset. I assume you would know if you have a parameterized query, is it possible you have a parameter on one of your datasets?

john.knapp 25 Posting Whiz in Training

Look at your code again...

Your Select Case e.ColumnIndex ... Case 8 is where the CellStyle.BackColor is set. As currently coded, That code can only affect Columns(8). To affect the previous column, you either have to move the Else statement up to that block, or reference that cell when setting the backcolor.

john.knapp 25 Posting Whiz in Training

When you say "Column 8" is that a 1-based count, or 0-based as in Columns(8)?

I'm only seeing Columns 8 & 9 in your Select statement, unless you changed the DataGridView column indexes to start at 1.

Assuming the DataGridView does indeed have a 0-based column index, your BackColor = Color.Red code can only affect Columns(8) - which would be the 9th column.

I'm a bit confused now...

john.knapp 25 Posting Whiz in Training

From what I see in a Google Search using that error, and in particular this discussion, it appears to be an issue with the way your data is bound to the DataGridView.

john.knapp 25 Posting Whiz in Training

The error I see is DataGridViewComboBoxCell value is not valid, is that the same error you get?

The default error message also says to handle the data error event, did you do that? If not, add this code to Form1.vb

Private Sub StudentsDataGridView_DataError(ByVal sender As Object, _
                                          ByVal e As DataGridViewDataErrorEventArgs) _ 
                                           Handles StudentsDataGridView.DataError
    If e.Exception IsNot Nothing Then
        MessageBox.Show(e.Exception.Message, e.Exception.Source)
    End If
End Sub
john.knapp 25 Posting Whiz in Training

That's a different error though, right? That error indicates that you are setting up a parameterized query, but not actually passing a parameter to it - do you have code where you assign a value to the parameter?

Back to the original error and query string with the DataType Mismatch - you're using an integer value in your WHERE FormNo = clause, but you're passing a string value.

Instead of: myCommand = New OleDbCommand("SELECT * FROM tbleMember WHERE FormNo='" & cmbName.SelectedValue.toString & "'", MyConn)

Try this:
myCommand = New OleDbCommand("SELECT * FROM tbleMember WHERE FormNo=" & cmbName.SelectedValue.ToString, MyConn)

john.knapp 25 Posting Whiz in Training

I'll let you know what I find

john.knapp 25 Posting Whiz in Training

Too late, the OP is banned now...

john.knapp 25 Posting Whiz in Training

In your SQL query, you're passing FormNo as a string, if it's an int value in the DB, that's your problem. See this post for an explanation.

john.knapp 25 Posting Whiz in Training

Does it give you the expression?

john.knapp 25 Posting Whiz in Training

I still highly recommend Try..Catch blocks in all your procedures.

john.knapp 25 Posting Whiz in Training

Post the code you have so far.

john.knapp 25 Posting Whiz in Training

To start with - you need Try...Catch blocks
The only one I see (other than the designer generated) is in Module1.GetShellIconAsImage

john.knapp 25 Posting Whiz in Training

What is the text (and details, if any) of the error?

john.knapp 25 Posting Whiz in Training

Clean your solution first, then zip and upload entire project

john.knapp 25 Posting Whiz in Training

My first piece of advice is to turn on "Option Strict"
Right-Click Project in Solution Explorer -> Select Properties (last item on context menu)
Select Compile Tab -> "Option Strict" -> click dropdown and select "On"

Rebuild your application, resolve those 2 errors regarding implicit type conversions and see what happens.

john.knapp 25 Posting Whiz in Training

In the future, please "clean" your project/solution before compressing and uploading.
It saves everyone time and diskspace...

john.knapp 25 Posting Whiz in Training

This is that same project I already helped on, right?
If you zip and upload it to rapidshare, I'll take a look

john.knapp 25 Posting Whiz in Training

The first two things that come to mind are this:

  1. Does pdfSharp require an assembly on the client machine
  2. Does Acrobat exist at that path on the client machine
john.knapp 25 Posting Whiz in Training

Please confirm that I understand.

If I understand correctly, you can:

  1. Determine which database to connect.
  2. Connect to either database per user choice in ComboBox.
  3. Retrieve the correct data.
    All at runtime

Is that correct?

john.knapp 25 Posting Whiz in Training

Create a parameter for your SQL query. See this discussion for sample code.

john.knapp 25 Posting Whiz in Training

Why are you filling the ComboBox from the SelectedIndexChanged event? I would've used the Form_Load event to call a FillCombo() subroutine.

The ComboBox supports "TypeAhead" natively with the AutoCompleteMode & AutoCompleteSource properties. There is also a sample project here on CodeProject that fills that source from a DataTable, the code is in C# - but it will give you a good start.

You'll probably want to handle the ComboBox_Leave event to make sure the user doesn't add tables to your DB though... ;)

john.knapp 25 Posting Whiz in Training

Have you tried putting the data in a ListView and then printing that?

john.knapp 25 Posting Whiz in Training

With that class, and this procedure in your Button_Click event:

Protected Sub Button1_Click(ByVal sender As Object, _
                            ByVal e As EventArgs) Handles Button1.Click

    Dim ControlsToValidate() As Control = {checkbox1, checkbox2, checkbox3, _
                                checkbox4, checkbox5, checkbox6, checkbox7, _
                                checkbox8, checkbox9, RadioButton1, _
                                RadioButton2, RadioButton3, RadioButton4}

    Dim myValidator As New ControlValueValidator()
    For Each myControl As Control In ControlsToValidate
        myValidator.ValidateControl(myControl)
        If Not myValidator.IsValid Then
            ' control is invalid, notify user
        End If
    Next

    ' if we're all done with the Collection, let's free up the resources
    Erase ControlsToValidate

End Sub

I get the following debug output:

checkbox1 is not checked.
checkbox2 is not checked.
checkbox3 is not checked.
checkbox4 is not checked.
checkbox5 is not checked.
checkbox6 is not checked.
checkbox7 is not checked.
checkbox8 is not checked.
checkbox9 is not checked.
RadioButton1 is not checked.
RadioButton2 is not checked.
RadioButton3 is not checked.
RadioButton4 is not checked.
john.knapp 25 Posting Whiz in Training

I am posting code for a partial class.
This partial class only checks TextBox, CheckBox, and RadioButton to evaluate whether the TextBoxes have text, CheckBoxes are checked, and RadioButtons are checked - it does not attempt to evaluate whether the RadioButtons are part of a set.

Since RadioButtons 1 & 2 are a set, one of those will be marked as invalid - even though it cannot be Checked=True if the other RadioButton in the set is already True. The same issue holds true with RadioButtons 3 & 4.
You will have to write your own code to evaluate these cases

  1. The class will return a Boolean value that you can check.
  2. Usage of the class is in the remarks section of the class.
  3. You have to code your own user notification.

Good Luck.

Partial Public Class ControlValueValidator
    '
    ' Partial Public Class ControlValueValidator
    ' Author: J.Knapp 2012-11-31 01:45 UTC
    ' Purpose: minimal validation to ensure ASP form controls have values
    ' - Currently supports only TextBox, CheckBox, and RadioButton
    ' - Does not evaluate RadioButton exclusivity|grouping
    '
    ' Usage Case 1:
    ' New myValidator(myControl)
    ' myValidator.IsValid = True | False | Nothing
    '
    ' Usage Case 2:
    ' New myValidator()
    ' myValidator.ValidateControl(myControl)
    ' myValidator.IsValie = True | False | Nothing
    '

    Private m_ValidationString As String
    Private m_IsValid As Boolean

    Public Sub New()
        m_ValidationString = "Control has not been validated."
        m_IsValid = Nothing
        Return
    End Sub

    Public Sub New(myControl As Control)
        ValidateControl(myControl)
        m_ValidationString = "Control has not …
john.knapp 25 Posting Whiz in Training

Of course it works, if it was untested code I would've said so! :)

john.knapp 25 Posting Whiz in Training

I've never used TextBoxEx, but you should be able to set the TextBox.Text property in your code, correct? I believe that you should be able to set that text property to vbNullString or "" without triggering an insert to your database (test this thoroughly!!!) - and setting that property after you aquire the data should override the display text in the textbox.

john.knapp 25 Posting Whiz in Training

What controls are you using to display the data?

john.knapp 25 Posting Whiz in Training

I'll try to replicate the isssue here, but not until later today

john.knapp 25 Posting Whiz in Training

Actually, even that ForeColor code works - ForeColor only affects the CheckBox.text property. You're probably looking for the label text to change instead

john.knapp 25 Posting Whiz in Training

Ok, thanks and good luck!

john.knapp 25 Posting Whiz in Training

but that was the user id of the database used by the admin.

See good explanation of why to not use sa here

john.knapp 25 Posting Whiz in Training

Scope_Identity() is always the primary key value of the last insert operation in the current user scope. You need a primary key on your data table or you're going to have issues. I'm too tired at the moment to think about whether that is causing issues in this particular query, but I think not - as long as you have a limited amount of data that you're working with anyway - say 10-15 numbers for testing.

For "Your_Identity_Column_Name" I entered the column name "Phone" which is what I am trying to match.

Nope. Use whatever you called your primary key column in the input : [Input].[ID]

john.knapp 25 Posting Whiz in Training

Your MsgBox function works - the ForeColor does not, correct?

That is because you are changing the property of a copy of the CheckBox object, and not rendering it.
That code I wrote was for a Windows Form - you can't change the ForeColor of the control like that in ASP.