TomW 73 Posting Whiz

There is no bin folder after deployment installation but as long as the database is in the same folder as the app.exe you can use the Application.StartUpPath method to determine the path to that folder.

Dim strDbFileName As String = ""
Dim strDatabaseSource As String = ""

strDbFileName = "myDatabase.mdb"
strDatabaseSource = IO.Path.Combine(Application.StartupPath, strDbFileName)
TomW 73 Posting Whiz

there that it sais Data source="path" i have inserted the whole path of my database and it works fine now, but i am afraid that it will not work on other pc because path will not be the same...how can i fix it?

On other Pc's is the database always in the same location? Such as the app folder, or special folder such as User\Local Settings\Application Data?

If so there you can code to find the full paths for these type of locations. If not you would have to provide a way for the user to specify where the database file is located.

TomW 73 Posting Whiz

In your database field: Id and identity seed?

TomW 73 Posting Whiz

Your code shows only a select statement. You mention the problem is after adding a row but your not showing the code for adding the row or getting the new field after adding it.

I dont have access installed to look at your db, not that i think that would help. But if you upload the form that is having problems, I'll take a look at the code to see if I can spot the problem.

TomW 73 Posting Whiz

You have to specify every single field that you want to search. You also have to specify if your looking for an exact match or perhaps one word (or even part of a word) within an individual field. For instance

Select *
From myTable
Where Column1 Like '%mySearchText%'
    Or Column2 Like '%mySearchText%'

The percent sign is a wild card telling it I dont care what letters/words are before or after my search text within that field. For exact matches you can simply use the equals sign followed by your search word(s).

Obviously that is if your are filtering during your actual query. To filter an already filled datatable, the method I mentioned earlier still applies. And yes you can add more then one column to be searched with that method. However searching every field is very process intensive I would suggest letting your database do that type of filter.

TomW 73 Posting Whiz

Just semantics/terminology but something to keep in mind, a datagridcontrol doesnt actually hold the data or connect directly to a database, you assign it a datasource such as a dataset/datatable etc... The underlying datasource is what you want to search & filter.

To answer your actual question, take a look at "DataView.RowFilter" in the help index. It will show you how to filter the data in your dataset/datatable and has an example. If you still need help just let me know.

TomW 73 Posting Whiz

I would have to disagree with the majority of the above reply. You should not be retrieving un-needed data from a database and holding it in memory. Write your query to get only the records that you need for this single user.


' You do not need to retrieve and store all users in your db.
' Likewise you don't need to retrieve all mail records.
' You have the login username, you only need a
' single table to query the records belonging to this user.

in my opinion what you should do id have two tables in your database one is "username" second is transaction.

Get the relation done between the 2 tables so that username is the primary key flield which is related to username in transaction table,many to one relationship.

' Again this is un-needed but just wanted to point out that
' you do not need seperate DataAdapters for every DataTable in
' a DataSet.
' Also I would suggest writing all your queries as stored procedures
' in whatever database you are using. It is more efficient, flexible
' and provides reusability for other datasets having the
' same queries within your app or other apps using the same db.

Now starting from vb.net editor code, you should add a tool
oledbconnection and 2 dataadapters because you have 2 tables. The wizard will open for the sql statement one …

TomW 73 Posting Whiz

Set the size of the form to the screen bound sizes. You will also need an API call in order to hide the taskbar; google, vb.net & Hide Taskbar

Me.Top = 0
Me.Left = 0
Me.Height = Screen.PrimaryScreen.Bounds.Height
Me.Width = Screen.PrimaryScreen.Bounds.Width
Me.FormBorderStyle = FormBorderStyle.None
TomW 73 Posting Whiz

Hello QBD, I understand your problem; unfortunately there is no easy solution. What you have to understand is like working directly in your database, any value changes you make to a cell dont truly take effect in that cell/record until you move to another record/row; at which time the new value is then validated and changes commited.

So even though the CellClick event may actuall fire each time its clicked (unlike most of the other events) its still not seeing that new value until you move to the next row.

The best that you can manage is checking that value when it does move to the next row in a consistent manner. The below event & sample triggers when you move to the next row, but will give you the changed value from the row you just left.

Private Sub dgv_CellValueChanged(...) Handles dgv.CellValueChanged

    Dim sbMsg As New StringBuilder

     With sbMsg
        .AppendLine(String.Format("Row Index: {0}", e.RowIndex))
        .AppendLine(String.Format("Column Index: {0}", e.ColumnIndex))
        .AppendLine(String.Format("Column Name: {0}", dgv.Columns(e.ColumnIndex).Name))
        .AppendFormat("Value: {0}", dgv.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
    End With
    MessageBox.Show(sbMsg.ToString)

End Sub
TomW 73 Posting Whiz

Theres a much easier way; you can get rid of the text boxes and use NumericUpDown (NUD) controls instead. The NUD is the same as a textbox but it will only allow numbers to be input. You can also set the min & max numbers allowed and whether or not you want to use a decimal point and how many places after the decimal if used.

When using the NUD through coding you will check for the Value property instead of the Text property that you would on a textbox.

TextBox2.Text = "1"

Also keep in mind that when working with a textbox, the above example is text, not actually a numeric datatype.

If you still need help with the textbox just let me know but I think the NUD is much much easier and you dont have to do as much validation or conversion back & forth between datatypes.

TomW 73 Posting Whiz

What exactly are you looking to have returned? (the entire line, the index of where the word starts etc) I can show you many different ways to search text but do you have a specific key word to search for?

One example:

Private Function IsFileContainsSrting(ByVal SearchWord As String, ByVal FileName As String) As Boolean
        Dim IsWordFound As Boolean = False
        Dim FileContents As String = String.Empty
        Dim FileStreamReader As StreamReader
        Try
            FileStreamReader = New StreamReader(FileName)
            FileContents = FileStreamReader.ReadToEnd()
        Catch ex As Exception
            MsgBox(ex.ToString) 
            IsWordFound = False
        Finally
            If FileStreamReader IsNot Nothing Then FileStreamReader.Close
        End Try

        If FileContents.IndexOf(SearchWord) > 0 Then
            'IndexOf returns -1 of not found and 0 if the textVal is empty
            IsWordFound = True
        End If

        Return IsWordFound

    End Function

Also there is the RegEx class that is very fast but more complicated to first start learning/using.

TomW 73 Posting Whiz

You would have to provide more details. Add the block of code that is causing the problem and also provide the exact error message.

TomW 73 Posting Whiz
TomW 73 Posting Whiz

There is no need to query the database multiple times for the same student record every time they click on an option.

Ardent, I would sugest starting by filling a DataTable with the (class) students you want to work with. Bind the Student Name to the DisplayMember of a Combobox and the StudentId to the ValueMember.

You can display the entire student table/records in a DataGridView (DGV) control with one line of code. When they select a student either from the ComboBox and/or a search TextBox, you can filter your DataTable (which you already have in memory) to display the selected record. Likewise when they double click on a record in the DGV you can bind the record fields right to there appropiate controls on a form for viewing/editing; without the need of re-querying the database or looping thru each record column to assign individual values to controls.

TomW 73 Posting Whiz
COMND.CommandText = "UPDATE  Tbl_Pat_Registration SET Pat_Name=@PPat_Name,Pat_ID=@PPat_ID where id=@Pid"

.AddWithValue("@Pid", Id)
            .AddWithValue("@PPat_Name", Trim(CChar(txt_name.Text)))
            .AddWithValue("@PPat_ID", Trim(CChar(Txt_id.Text)))

Is Id a numeric datatype,why are you converting it to a char?

.AddWithValue("@PPat_ID", cInt(Txt_id.Text.Trim))
TomW 73 Posting Whiz

If your database is located on a web server, both your web page and your desktop application can connect to that database and use it.

TomW 73 Posting Whiz

Your array is not actually zero length, it has a length of one!

strFile is an array. The array can either be "nothing" or have at least one element to it; even if it is blank.
strFile = strSubCommittees.Split("|")
This will automatically assign at least one element to your array, even if it is blank and doesnt actually have a value in that element.

Try this in a console app to see the results:

Sub Main()

        Dim strCommittees As String = ""
        Dim strFile() As String = Nothing

        If strFile Is Nothing Then
            Console.WriteLine("strFile() is nothing")
        Else
            Console.WriteLine("strFile.Length : {0}", strFile.Length)
        End If

        Console.WriteLine("'Read blank value into array")
        Console.WriteLine("strCommittees.Split(""|""c)")

        strFile = strCommittees.Split("|"c)
        Console.WriteLine("strFile.Length : {0}", strFile.Length)

        Console.ReadLine()

    End Sub
TomW 73 Posting Whiz

Have you tried stepping through the code in debug mode to make sure the event is actually firing with the expected parameter values and also that "ra" is returning a number stating whether or not any records were actually updated or not?

TomW 73 Posting Whiz

The height of a status strip is a set size. If you add an object such as a label to your status strip and change the statuslabel's font size to 28 (Tahoma), the statusstrip controls height would then change to 50.

TomW 73 Posting Whiz

You want to round to a specific demicial position (not ceiling function). You havent mentioned how/where this value is being displayed/stored to show a specific example.

In a database such as Sql Server, you can set the precision property of your decimal column to one, that will limit the values to 1 place passed the decimal point.

In VB, with a decimal datatype you can not limit the precision but you can format you numeric value for display using the FormatNumber function.

Sub Main()

        Dim decValue As Decimal = 4.18D

        Console.WriteLine("decValue : {0}", decValue)
        Console.WriteLine("Formatted decValue : {0}", FormatNumber(decValue, 1))
        Console.ReadLine()

    'Results
    'decValue : 4.18
    'Formatted decValue : 4.2

End Sub
TomW 73 Posting Whiz

I have a Crystal Report which has a background made up to match a work form that needs to be filled out with data queried & processed from the database. The finished report has only five single field values and up to six detail records (three fields in each detail record). The 6 detail records need to fit into a fixed size square/box on the background form and some of the individual values fit into fixed boxes below the details section. Since the detail section grows/shrinks depending on the amount of records displayed, the whole bottom of my form is thrown off when there are less then 6 records to display.

I’ve used a few workarounds in the past such as implementing a sub-report in the details section, padding additional blank records to be displayed, and even passing every value as an individual parameter. This produced the desired results but is inefficient and slow. I need to create and send these reports directly to printing as fast as possible and looking for a better way of fixing the size so that all the values remained aligned with the form areas.

TomW 73 Posting Whiz

Are you sure it needs to be crystal 9, any newer version should be backwards compatible and update the report?

TomW 73 Posting Whiz

You can not update your interface from a background thread. However you can use the ProgressChanged event of a background worker to update progress status. There are some examples available for download and additional walkthrough examples available in the help file, just type in "BackgroundWorker Class"

TomW 73 Posting Whiz
Private Sub CheckedListBox1_ItemCheck( ) 

        If CheckedListBox1.CheckedItems.Count >= 7 AndAlso e.NewValue = CheckState.Checked Then
            lblStatus.Text = "To many items selected"
            e.NewValue = CheckState.Unchecked
        Else
            'Items selected are under 7
            'or they are in the action of deselecting an item
            'clear error message
            lblStatus.Text = ""
        End If

    End Sub

And just as an additional tip, any control that you are assigning values too, you should give a meaningfull name too. Label37 means little when your scrolling through hundreds if not thousands of lines of code.

TomW 73 Posting Whiz

Why is there two blocks of code for the same CheckedListBox control?

Also this is not needed
e.NewValue = CheckState.Unchecked = CheckState.Unchecked = True

Change to simply:
e.NewValue = CheckState.Unchecked

and your label is not showing, because your setting it to a blank string

TomW 73 Posting Whiz

Anytime :)

TomW 73 Posting Whiz

My coding was in the CheckListBox's ItemCheck event, e is the event parameter that is automatically present if you are in the right control event. I truncated the control event parameters to save text but will show the whole line since it confused you.

Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck

TomW 73 Posting Whiz

Here lemme explain this better

Say i have 1 checked list box but i want to limit how many options people can click to 6 but when they hit 7 a label appears and say "To many options selected" but then gets rid of the 7th option they clicked

LOL, ok then its the reverse, through coding you would have to check the selected item count and prevent this.

Private Sub CheckedListBox1_ItemCheck( ) 

        If CheckedListBox1.CheckedItems.Count >= 7 AndAlso e.NewValue = CheckState.Checked Then
            Label1.Text = "To many items selected"
            e.NewValue = CheckState.Unchecked
        End If

    End Sub
TomW 73 Posting Whiz
TomW 73 Posting Whiz

There is no limitation to the amount of items you can select in a checkedlistbox. This sounds more like something in your code that is causing this.

TomW 73 Posting Whiz

MessageBox.Show(Now)

TomW 73 Posting Whiz

Hi,
I am trying to make a quiz and i want it so, that if you get the correct answer you go to the next form and close the previous one but if not, it will make pop-up box that goes back to the question when pressed OK. Here is what i have so far:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If (TextBox1.Text = "yes") Then Form3.Show() Else 
        MessageBox.Show("Try Again", "Incorrect", MessageBoxButtons.OK, MessageBoxIcon.Information)

Any help would be greatly appreciated!

Your click event is calling the same form to show, this is why you are seeing the same form pop up. You should declare a new instance of your form to show and close the existing one (if that is what you want.

for instance

If TextBox1.Text = "yes" Then 
    Dim frm As New Form3 '(are you trying to show the same form repeatedly?)
   frm.Show
   Me.Close
End If

Using End instead of calling the forms close method is obselete and not recommended in .Net

TomW 73 Posting Whiz

Here are is a function I use, it will import an Excel worksheet into a dataset/datatable for you. After you get that much working, you can manipulate/format your data and then transfer it to your database.

'Calling Sub

Dim dtExcel As New DataTable
dtExcel = ImportExcelIntoDataTable(YourFileName)

'Just to view the imported results
DataGridView1.DataSource = dtExcel
Private Function CreateExcelConnectionString(ByVal strFile As String, Optional ByVal blnHeader As Boolean = True) As String

        Dim bldrCon As New OleDb.OleDbConnectionStringBuilder
        bldrCon("Provider") = "Microsoft.Jet.OLEDB.4.0"
        bldrCon("Data Source") = strFile

        'blnHeader specifies whether a header row is included or not
        'IMEX=1; - Tells the driver to read everything as intermixed text

        If blnHeader = True Then
            bldrCon("Extended Properties") = "Excel 8.0;HDR=YES"
        Else
            bldrCon("Extended Properties") = "Excel 8.0;HDR=NO"
        End If

        Return bldrCon.ConnectionString

    End Function

Public Function ImportExcelIntoDataTable(ByVal strFile As String, Optional ByVal strWorkSheet As String = "Sheet1", Optional ByVal blnHeaderRow As Boolean = True, Optional ByVal blnDataAsText As Boolean = True) As DataTable

        Dim dtXls As New DataTable
        Dim strDbCon As String = ""

        'Connection string to Excel file
        strDbCon = CreateExcelConnectionString(strFile, blnHeaderRow)

        Using con As New OleDbConnection(strDbCon)
            Dim daXls As New OleDbDataAdapter("Select * From [" & strWorkSheet & "$]", con)
            daXls.Fill(dtXls)
        End Using 'con

        Return dtXls

    End Function
TomW 73 Posting Whiz

Anytime... :)

TomW 73 Posting Whiz
DateTimePicker1.Value = Now.AddHours(2)
TomW 73 Posting Whiz

Defend it all you want but the fact is; it is obselete. I can sit here an argue that Cobol was a great language or that Windows NT was the best operating system but there time has gone and a programmer needs to update with the ever changing technologies or be limited in a job search to companies that are unwilling to update.

kvprajapati commented: It is not obselete. Good suggestion +5
TomW 73 Posting Whiz

Again your first link is to a version the user stated he wasnt using and your second link even confirms it is not a reserved word for the program!

TomW 73 Posting Whiz

It is over a decade since its release and 3 verisons of the language have been released sinece. Saying otherwise doesnt change the fact that it is obselete!. And to say there is not much new in .Net only shows your lack of knowledge on the subject.

TomW 73 Posting Whiz

The example shows how you can filter data in a datatable, obviously you have to replace the values with the appropiate column names and search values you want.

TomW 73 Posting Whiz

VB6 came out in 1998, why would you tell someone just starting out to start with a language that is obselete by a decade....

TomW 73 Posting Whiz

Your link is to Access 2003 but the original poster mentions using a different version (2007).

Access 2007 reserved words and symbols

TomW 73 Posting Whiz

For the most part I absolutely agree with Sknake above. However in certain situations, such as working with the same group of records over & over that Im not updating only filtering for a result, I do find it useful to hold the date in memory rather then run a new query every minute.

With that said, with data that you are updating which it seems you are updating one record at a time here, it will only take milliseconds to query and return only the record(s) you want to work with. This outweighs the cost of keeping an entire table in memory.

Searching for Data in the DataSet
When querying a DataSet for rows that match particular criteria, you can increase the performance of your searches by taking advantage of index-based lookups. When you assign a PrimaryKey value to a DataTable, an index is created. When you create a DataView for a DataTable, an index is also created. Here are a few tips for taking advantage of index-based lookups.

• If the query is against the columns that make up the PrimaryKey of the DataTable, use DataTable.Rows.Find instead of DataTable.Select.

• For queries involving non-primary key columns, you can improve performance for multiple queries of the data using a DataView. When you apply a sort order to a DataView, an index is built that is used when searching. The DataView exposes the Find and FindRows methods to query the data in the underlying DataTable.

TomW 73 Posting Whiz
Set column2 ='C2sample1'
WHERE column2 = 'C2sample1'"

If Column2 already equals C2Sample1, then your replacing the column value with the same exact value that your searching for.

TomW 73 Posting Whiz

Oh you didnt even mention the data was database driven, the datasets will definitely be of great value. With a database I can simply drag & drop the tables I want into a typed dataset and the matching table structures are automatically generated. Retrieving (also inserting, updating & deleting) the data is merely a matter of adding the queries to TableAdapters or DataAdapters and calling them. My personal preference though is not to put any hard coded queries within my program(s) and instead put them right into Stored Procedures in the database and then just call the SP from the program adapters.

I'll put some Ado.Net tutorial links that should get you started. If your interested in books, I have some recommendations.

(no particular order in which to start with)
ADO.Net
Data Walkthroughs 1
Data Walkthroughs 2

TomW 73 Posting Whiz

A DataGridView control is simply a means of displaying the data from its datasource (dataset or datatable). Even if changing and storing your data in a DataSet, you can still display the data in a ListView if you choose too.

To answer your actual question, yes you can dynamically add columns to your "DataTable" that will then appear in your DataGridView. And yes editing records is very easy and I will be here to help :)

TomW 73 Posting Whiz

You can create a dataset/datatable and add a column for each field you are currently using as a seperate array. You can then add, edit, delete records as needed. A datatable will give additional advantages such as giving you search, filtering and sorting capabilites. You would also have the options to create relations between tables if needed. Such as if column1 (student) has many column2 (classes) you can easily define two seperate tables within the dataset and automatically link the records defining a relationship. The end result is simply passing back the dataset/datatable from the function. Also with a single call you can read/write all the data to an xml file.

TomW 73 Posting Whiz

The variable will no longer need to be "Static" since its scope is in existence for the life of the form itself. This would be refered to as a module level variable (hence the "m_" prefix to signify its scope) or form level.


Public Class Form1

Dim m_CountDown As New TimeSpan(0, 1, 0)

Private Sub Form1_Load() ... End Sub End Class[Code=VB]

Public Class Form1

Dim m_CountDown As New TimeSpan(0, 1, 0)

Private Sub Form1_Load()
...
End Sub
End Class

TomW 73 Posting Whiz

The variable will no longer need to be "Static" since its scope is in existence for the life of the form itself. This would be refered to as a module level variable (hence the "m_" prefix to signify its scope) or form level.

Public Class Form1

Dim m_CountDown As New TimeSpan(0, 1, 0)

Private Sub Form1_Load()
...
End Sub
End Class
TomW 73 Posting Whiz

01) Set the DropDownStyle to "DropDown" to allow editing
AutoCompleSource = ListItems
And
AutoCompleteMode = Append or SuggestAppend depending on if you want the items automatically selected or just suggested.

TomW 73 Posting Whiz

Sounds perfect for records in a datatable rather then a seperate array for each column.