TnTinMN 418 Practically a Master Poster

Use one of these forms of parsing:

i = Integer.Parse("1") - will throw an exception if conversion is not possible
Integer.TryParse("1", i) - will not throw exception, leaves i unchanged

TnTinMN 418 Practically a Master Poster

I think the problem that you where having is the order that that you where adding the parameters.

OleDB ignores the parameter names and substitutes them in sequential order. In the SQL CommandText, you could type pretty much any unquoted text where it expects a value and it will treat it as a placeholder. Placeholders are filled Left to Right with the parameters in the order that the parameters exist in the parameter collection. This is why the documentation shows using "?" as placeholders.

     Dim cmd2 As New OleDb.OleDbCommand("UPDATE tbl_Customers SET cust_Company=@cust_Company WHERE CustomerID=@CustomerID", conn)
    cmd2.Parameters.Add("@CustomerID", CustomerIDTextBox.Text)
    cmd2.Parameters.Add("@cust_Company", Cust_CompanyTextBox.Text)

In this case you were add the ID field first when it should have been added second. DB's example had it in the correct order. This could have been written:

     Dim cmd2 As New OleDb.OleDbCommand("UPDATE tbl_Customers SET cust_Company=@cust_Company WHERE CustomerID=@CustomerID", conn)
     cmd2.Parameters.Add(Nothing, Cust_CompanyTextBox.Text)
     cmd2.Parameters.Add(Nothing, CustomerIDTextBox.Text)
TnTinMN 418 Practically a Master Poster

I believe you are going to have to normalize and strip the diacritics from the string first.

see: http://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net

You could add new column to your datatable with the processed string and then do the row filter against that processed string.

Or you could use LINQ to create a list of datarows and use that presumably as a datagridview.DataSource.

Something like this:

List<DataRow> rows = (from row in dt.AsEnumerable() 
                      where System.Text.RegularExpressions.Regex.IsMatch(RemoveDiacritics(((DataRow) row)[0].ToString()), "Maria*") 
                      select row).ToList();
TnTinMN 418 Practically a Master Poster
TnTinMN 418 Practically a Master Poster

infor = false

I think that should be Info=false;

deceptikon commented: Good catch +12
TnTinMN 418 Practically a Master Poster

Try using the CellClick event not CellContentClick event handler.

   Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvEmployee.CellClick
      TextBox1.Text = dgvEmployee.Rows(e.RowIndex).Cells(0).Value.ToString()
      TextBox2.Text = dgvEmployee.Rows(e.RowIndex).Cells(1).Value.ToString()
      TextBox3.Text = dgvEmployee.Rows(e.RowIndex).Cells(2).Value.ToString()
   End Sub
TnTinMN 418 Practically a Master Poster

Sure it is doable! You just have to code it. :))

Here is a crude implementation of a custom textbox with this capability. You have to double click on a item to select it. You could change that to single click if you want. You may need to change the "@" detection algorithm. It works with a standard US keyboard with "@" = shift-2.

There is no error checking; I leave that to you.

Public Class AutoCompleteDropDownTB
   Inherits TextBox
   Public WithEvents dropdown As New ListBox
   Private frmDropDown As New Form

   Public Sub New()
      dropdown.Parent = frmDropDown
      dropdown.SelectionMode = SelectionMode.One

      With frmDropDown
         .FormBorderStyle = FormBorderStyle.None
         .Size = dropdown.Size
         .Visible = False
         .StartPosition = FormStartPosition.Manual
         .TopLevel = True
         .TopMost = True
      End With
   End Sub

   Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
      If e.Shift AndAlso e.KeyCode = Keys.D2 AndAlso Not Text.Contains("@"c) Then
         ShowDropDown()
      End If
      MyBase.OnKeyDown(e)
   End Sub

   Private Sub ShowDropDown()
      dropdown.SelectedIndex = 0 ' make sure 1st item is selected
      Dim offset As Int32
      If BorderStyle = Windows.Forms.BorderStyle.Fixed3D Then
         offset = 2
      Else
         offset = 0
      End If

      With frmDropDown
         .Location = PointToScreen(New Point(0, Size.Height - offset))
         .Show()
      End With
   End Sub

   Private Sub dropdown_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dropdown.DoubleClick
      frmDropDown.Hide()
      Text &= dropdown.SelectedItem.ToString
      SelectionStart = TextLength
   End Sub

   Private Sub dropdown_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles dropdown.LostFocus
      frmDropDown.Hide()
   End Sub
End Class

Just add this to your project and rebuild. It should show up at the top of your toolbox.

Example …

TnTinMN 418 Practically a Master Poster

I think you upload code is incorrect.
Here is a translated version of the code MS has at: How to: Upload Files with FTP

      ' Get the object used to communicate with the server.
      Dim request As Net.FtpWebRequest = CType(Net.WebRequest.Create("ftp://www.contoso.com/test.htm"), Net.FtpWebRequest)
      request.Method = Net.WebRequestMethods.Ftp.UploadFile

      ' This example assumes the FTP site uses anonymous logon.
      request.Credentials = New Net.NetworkCredential("anonymous", "janeDoe@contoso.com")

      ' Copy the contents of the file to the request stream.
      Dim sourceStream As New IO.StreamReader("testfile.txt")
      Dim fileContents() As Byte = System.Text.Encoding.UTF8.GetBytes(sourceStream.ReadToEnd())
      sourceStream.Close()
      request.ContentLength = fileContents.Length

      Dim requestStream As IO.Stream = request.GetRequestStream()
      requestStream.Write(fileContents, 0, fileContents.Length)
      requestStream.Close()

      Dim response As Net.FtpWebResponse = CType(request.GetResponse(), Net.FtpWebResponse)

      Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription)

      response.Close()
TnTinMN 418 Practically a Master Poster

…so why do it the other way, ie ole I guess whatever that is

I’ll try to explain this to the best of my ability. I may get some of the facts and terminology mixed up though. I never was one for all the fancy computer science terminology.

ADO,Net is the basis for all .Net database interfacing. OleDB is layer above ADO that provides addition tools to manipulate the data and interface with the other .Net data classes such as a DataSet.

See: Overview of ADO.NET

. Is there any advantage of using one over the other?

The choice comes down to selecting the correct tool for the given task and whether or not you know how to use that tool.

For a case like appending a record to datatable, you could go either route. You could also have used OLEDBCommand with a SQL “Insert” statement to do the same thing directly as that convoluted code shown above that was crafted to prevent the need for you to generate the “Insert” SQL yourself (i.e. same destination, but a different path).

The biggest advantage is when you use the full design functionality of Visual Studio for creating a “Data Access Layer” in the graphical environment. Many people will create a dataset on the fly in their code just to make work with selected abstraction layer like OleDB or SQLClient without ever realizing that there is so much more that they can accomplish in they just …

TnTinMN 418 Practically a Master Poster

System.Data.OleDb.OleDbConnection' cannot be converted to 'System.Data.SqlClient.SqlConnection

To be blunt about what BegginnerDev alluded to:

Which warrants the question, why are you cross calling the SQLClient and OLEDB libraries?

change: Dim constr as new OleDb.OleDbConnection

to: Dim constr As New SqlConnection

Also, why are you creating and immediately disposing the adapter and dataset?

Disposing of data objects is a good idea, but do it in the correct sequence.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Dim constr As New System.Data.SqlClient.SqlConnection
   constr.ConnectionString = "Provider=localhost;data source=C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\APP V1.2\APP V1.2\DATABASE1.MDF"
   Dim sqlstr As String = "select * from Table1 where StudentID=" & TextBox1.Text
   Dim ds As New DataSet
   Dim apt As New SqlDataAdapter
   Try
      apt = New SqlDataAdapter(sqlstr, constr)
      apt.Fill(ds)
      DataGridView1.DataSource = ds.Tables(0)
   Catch ex As Exception
      MsgBox(ex.Message.ToString)
   Finally
      constr.Dispose()
      apt.Dispose()
   End Try
End Sub
TnTinMN 418 Practically a Master Poster

Your welcome.

Please close this thread out if you don't have any more questions.

TnTinMN 418 Practically a Master Poster

Sorry, I typed out those comments to quickly. If you have the OFD.CheckFileExists set to True (the default setting) then that code block could be like this:

    Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog.FileOk

        TextBox1.Text = OpenFileDialog1.FileName.ToString()

        ' Display the image

        PictureBox1.ImageLocation = OpenFileDialog1.FileName ' this will also load the file

        Button2.Show()
        Button3.Show()

    End Sub
TnTinMN 418 Practically a Master Poster

The form deactivate/Activate only seems to occur in you use the MonthCalendar dropdown to make the selection.

It probably has to do with the MonthCalendar control being displayed a Modal window (like a dialog box) and it taking focus (hence the deactivation of the form) when clicked on. The form is reactivated when the MonthCalendar closes.

TnTinMN 418 Practically a Master Poster

On which button click did the error occur?

Here are some recommended changes:

    Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs)
       ' Dim strm As System.IO.Stream       delete this and the next line
       ' strm = OpenFileDialog1.OpenFile()
        TextBox1.Text = OpenFileDialog1.FileName.ToString()
        If Not (strm Is Nothing) Then
            ' Display the image

            ' Since you are using ImageLocation in Button2_Click change the next line

           ' PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)

           ' to this:

            PictureBox1.ImageLocation = OpenFileDialog1.FileName ' this will also load the file

            Button2.Show()
            Button3.Show()
        End If
    End Sub

Also: Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs)

should be: Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

TnTinMN 418 Practically a Master Poster

Just posting this as a FYI as a potential source for low cost reference books, if you don't have a problem buying used books.

For the one deceptikon referenced:

http://www.biblio.com/search.php?author=cormen&title=Introduction+to+Algorithms&keyisbn=&format=

p.s.: I should mention that they can be shipped from all over the world, so it may take a few weeks for you to get the book.

TnTinMN 418 Practically a Master Poster

I want to set the focus only the first time the form is loaded, from that point on I want the tab control to dictate the navigation.

Then use either the Form.Shown event or Form.Load event.

TnTinMN 418 Practically a Master Poster

No. You did not do anything wrong.

A line of code got deleted when I was editing it while posting. :(

Add dt.Rows.Add(r) somewhere before the statement: da.Update(New DataRow() {r})

I am a VB6 man at heart and it is so easy to do this on VB6

Then you are probably more comfortable with ADO. Use it then. I'm a bit rusty with ADO, but I believe that this should do the trick once you add the adodb reference. It worked on my quick test.

Remember to to make the needed changes to the connection string (in cn.open) and TableName (in the rs.Open).

     ' Add Project .Net Reference to adodb.  see:  http://support.microsoft.com/kb/318559

      Dim cn As New ADODB.Connection
      Dim rs As New ADODB.Recordset

      cn.Open(My.Settings.PlayConnectionString)

      rs.Open(Source:="History", ActiveConnection:=cn, CursorType:=ADODB.CursorTypeEnum.adOpenDynamic, LockType:=ADODB.LockTypeEnum.adLockOptimistic)
      rs.AddNew()
      rs.Fields.Item("Datee").Value = Now
      rs.Fields.Item("ContactID").Value = contactID
      rs.Fields.Item("Userr").Value = username
      rs.Save()
      cn.Close()
TnTinMN 418 Practically a Master Poster

UKnod,

That code is just plain nasty! :(

It appears that you want to add a new record to the History table in the database. You have created a dataset (ds5) elsewhere in your code.

Does your code need to access the dataset's History table elsewhere, or do you create it just for the purpose of adding a new row?

If you do not need to maintain records in memory, you could do something like this:

      ' Modify the following line to reflect your connection string
      Dim cn As New OleDbConnection(My.Settings.PlayConnectionString)

      'create command to use
      Dim cmd As New OleDbCommand("History", cn)
      cmd.CommandType = CommandType.TableDirect

      ' create a dataadapter and commandbuilder for it

      Dim da As New OleDbDataAdapter(cmd)
      Dim cb As New OleDbCommandBuilder(da)

      ' create a temporary table to hold History's schema
      Dim dt As New DataTable

      ' Fill the schema so that we can get the row template NewRow
      da.FillSchema(dt, SchemaType.Source)

      Dim r As DataRow = dt.NewRow

      r(6) = contactID
      r(1) = Now()
      r(3) = username

      ' process the new row
      da.Update(New DataRow() {r})

      ' cleanup
      cb.Dispose()
      da.Dispose()
      cmd.Dispose()
      cn.Dispose()

This code could be shorter if you would post the History table's schema (field definition listing) and note the keyed fields. Knowing the schema would allow creating an insert command and the datatable code could be eliminated.

TnTinMN 418 Practically a Master Poster

Is the dgv StudentList backed by a datatable? If so, add a boolean column (call it Selected)to the datatable then create two dataviews. Then create two dataviews filtered on the new column being either true (Selected) or false and use the dataviews as the datasource for the respective datagridviews. Then you only need to set the Selected field in your botton's click handler.

TnTinMN 418 Practically a Master Poster

Hi ddanbe,

I'm glad you found a new toy to play with. :)

You may find these examples useful: Samples Environment for Microsoft Chart ControlsClick Here

The chart control was also made available for .Net 3.5 as a separate library.

Microsoft Chart Controls for Microsoft .NET Framework 3.5Click Here

ddanbe commented: A little late, but great advise! +14
TnTinMN 418 Practically a Master Poster

I like using datatables and a rowfilter for this type of stuff.

Here is a simple example. I manually loaded the DataTables, but you would do this with your file contents. You could also do your text files as xml and load the table directly with the xml definition. Most of the code is just creating some data to play with.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private DataTable dtGenre = new DataTable();
        private DataTable dtMovies = new DataTable();

        private void Form1_Load(object sender, EventArgs e)
        {
            DataRow r = default(DataRow);

            // Build Movies Table

            dtMovies.Columns.Add("Genre", typeof(string));
            // add whatever columns you need
            dtMovies.Columns.Add("Title", typeof(string));
            dtMovies.Columns.Add("Description", typeof(string));
            dtMovies.Columns.Add("Rating", typeof(string));

            // just defining Genre and title for this example
            r = dtMovies.NewRow(); r[0] = "Action"; r[1] = "Title1"; dtMovies.Rows.Add(r);
            r = dtMovies.NewRow(); r[0] = "Action"; r[1] = "Title2"; dtMovies.Rows.Add(r);
            r = dtMovies.NewRow();r[0] = "Action"; r[1] = "Title3"; dtMovies.Rows.Add(r);
            r = dtMovies.NewRow(); r[0] = "Adventure"; r[1] = "Title4"; dtMovies.Rows.Add(r);
            r = dtMovies.NewRow(); r[0] = "Comedy"; r[1] = "Title5"; dtMovies.Rows.Add(r);
            r = dtMovies.NewRow(); r[0] = "Comedy"; r[1] = "Title6"; dtMovies.Rows.Add(r);

            dtMovies.DefaultView.RowFilter = null;

            // Build Genre Table
            dtGenre.Columns.Add("Genre", typeof(string));
            dtGenre.Columns.Add("Description", typeof(string));
            r = dtGenre.NewRow(); r[0] = "Action";
            r[1] = "Action: Usually include high energy, big-budget physical stunts and chases, possibly with rescues, battles, fights, escapes, destructive crises (floods, explosions, natural disasters, fires, etc.), non-stop motion, spectacular rhythm and …
TnTinMN 418 Practically a Master Poster

It looks like your code is to automatically login to some site. Presumably you would only want to do this login once, so try adding a boolean check to prevent the login code from running on each Doc_complete event. Or instead of WebBrowser1.Url, use a Url variable set to the login page an test that against e.Url.

   Private LoggedIn as Boolean = False
   Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
      If WebBrowser1.Url = e.Url Then
         If Not LoggedIn then
            LoggedIn = True
            ' Run your login code
         End If
      End If
   End Sub

   ' Or 

      Private urlLogin as Uri = New Uri("www.loginaddress")
   Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
      If urlLogin = e.Url Then

            ' Run your login code

      End If
   End Sub
TnTinMN 418 Practically a Master Poster

give this pattern a try

   Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
      If WebBrowser1.Url = e.Url Then
         ' this is the one you want
         ' run your code against WebBrowser1.Document
      End If
   End Sub
TnTinMN 418 Practically a Master Poster

Are you using a relative or absolute path. If it is a relative path, it will be relative to the current working directory.

Try adding this to your code to retrieve the PictureBox's error reason.

   Private Sub CompanyLogo_LoadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles CompanyLogo.LoadCompleted
      If e.Error IsNot Nothing Then
         MsgBox(e.Error.Message)
      End If
   End Sub
TnTinMN 418 Practically a Master Poster
TnTinMN 418 Practically a Master Poster

My opinion excel is the worst choice. Access is nearly as bad.

I would go with either SQL Server Compact or Sql Server Client.

TnTinMN 418 Practically a Master Poster

now the question is how can i get the that name to be used in my query?
using loop?
i will use it to be the name of my table i want to search.

I hope you understand what i mean.

Nope!, I do not understand.

Do you mean that you want to retrieve a list of Table names from the DB and be able to substitute the Table name in the query?

This example is for a SQLClient connection, but should work for OleDb as well.

   Dim cn As New SqlClient.SqlConnection(My.Settings.NorthwindConnectionString)
   cn.Open()
   For Each r As DataRow In cn.GetSchema("Tables").Rows
      ' Note that this will pull both Tables &" Views.  You may need to filter out the Views.
      Dim TableName As String = r("Table_Name").ToString
      ' do something with TableName
   Next
   cn.Close()
TnTinMN 418 Practically a Master Poster

Since you state that you are using a VB Express Edition, this question should be moved to the VB.Net forum.

Depending on the volume of data and security needs, you could use any of the options you listed, but I would stay away from using Excel files since that option will provide very limited DB functionality. If you foresee a need to dump a set of data out for use in Excel, there are several options available for doing this.

For a simple DB structure and relatively small amount of data, you could use the .Net DataTable class to save/load your data to/from an XML file. Your DB would be held in memory once loaded.

MS Access can be a pain in regards to the driver bitness. You can not have both 32 and 64 bit versions of the driver installed.

Another option to consider is SQL CE that is very light weight and gives an easy upgrade path to SQL Server if that need would ever become necessary. You should have been given an option to install it when you installed VB express (at least with the more recent versions).

And as Jim already mentioned, you could always install SQL Server Express.

TnTinMN 418 Practically a Master Poster

Hi Dj,

I know that this type of error can be frustrating, but it is happening for a logical reason.

When you start application, an instance of Form1 is created. During it's creation the form level variables are created first.

The problem is occuring with this statement:

Dim myUri As New Uri(Me.ComboBox1.Text)

At this point in the initialization of the form, ComboBox1 may be declared but does not yet have an instance of the ComboBox class assigned to it.

If you were to right-click on ComboBox1 in this statement and select "Go To Definition", then Form1.Designer.vb file will open and you will be positioned at it's declaration statement at the bottom of the file. If you scroll up to the start of "Private Sub InitializeComponent()" you will see a the statement:

Me.ComboBox1 = New System.Windows.Forms.ComboBox

This statement is where an instance of Combox is assigned to ComboBox1, but this does not occur until InitializeComponent is called by default "Sub New" of the Form class.

So much for the reason for the problem. Now to remedy the problem.

Change: Dim myUri As New Uri(Me.ComboBox1.Text)

To: Dim myUri As Uri

Add a Form load handler:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   If Not String.IsNullOrEmpty(Me.ComboBox1.Text) Then myUri = New Uri(Me.ComboBox1.Text)
End Sub

You may want to add a similar "If" statement in "Sub ComboBox1_Change" to verify that the text is not empty before creating a Uri from it.

PS: I just took another look at …

TnTinMN 418 Practically a Master Poster

@ddanbe: You are welcome. :) VB has a few utility classes that they really should publicize better to the .Net world or better yet, move to generic Utility namespace.

TnTinMN 418 Practically a Master Poster

The error may be in the checkbox_checked handler logic. You are obviously setting "Statustype" and "customerID" at some point in your code and then calling this method; are you sure that the values that exists when this method is call are correct and matches "Statustype" a field in the table?

Try adding this statement right after your Dim UpdatequeryString As String = statement to observe the query generated.

Debug.WriteLine(UpdatequeryString)

This will write to the Immediate Window (press: cntrl-Alt-I to open this window in VS).

TnTinMN 418 Practically a Master Poster

You should calculate the monthly payment once based on the initial loan amount and not in your loop based on remaining balance.

Are you using the Financial Class from the VisualBasic Namespace? If so, then your usage is incorrect and you should review the documentation.

ddanbe commented: Great answer +14
TnTinMN 418 Practically a Master Poster

look at your code with a bit of formatting.

Do Until rs.EOF

    If rs!RegNo = Text2.Text Then
        If IsNull(rs("Name")) Then
            answer = MsgBox("The Register Number You Entered Didnt Provide All The Inforamtion Do you still Want to Display the Details", vbYesNo + vbExclamation, "Alert")
            If answer = vbYes Then
                Text1.Text = rs!Name
                Text3.Text = rs!MobileNo
                Text4.Text = rs!E_mailId
                Text5.Text = rs!ArrearYear
                Text6.Text = rs!ArrearSemester
                Text7.Text = rs!ArrearSubject
                Text8.Text = rs!HOA
                    If answer = vbNo Then
                        Form1.Show
                    Else
                        rs.MoveNext
                    End If

This Loop statement is isolated withing an if-then block without a Do Statement to pair with

                Loop


                MsgBox "THE REGISTER NUMBER U ENTERED DOES NOT HAVE HISTORY OF ARREARS"
                rs.Close

You can not isolate parts of statement pairs in another paired statement block like If-End IF.

TnTinMN 418 Practically a Master Poster

If StatusDate.Year <> "1900" Then

Assuming "StatusDate" is a DataTime structure, then the "Year" method should be returning an integer value and not a string. Put Option Strict On at the top of your code and see how many other issues the IDE flags for you.

I'm not saying this is the source of you current problem, but it is indicative of some sloppy coding.

Also, what is special about 1900? It is not the default year for an unset date value; date values initialize to 1/1/0001.

TnTinMN 418 Practically a Master Poster

You are welcome.

Please close this thread out if your problem is solved.

TnTinMN 418 Practically a Master Poster

"Sender" typically is the control prompting the call to the event handler method. Cast it to the type of control you hope it is after a bit of chgecking first.

   Private Sub Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
      If sender IsNot Nothing AndAlso TypeOf sender Is Label Then
         Dim lbl As Label = CType(sender, Label)
         MsgBox(lbl.Text)
      End If
   End Sub
TnTinMN 418 Practically a Master Poster

You need to retrieve the command-line arguments, if any, and test the first argument. It should be the file that launched the application.

        Dim fi As IO.FileInfo ' used to test for file properties
        If My.Application.CommandLineArgs.Count > 0 Then
            fi = New IO.FileInfo(My.Application.CommandLineArgs(0))
            If fi.Exists Then
                Select Case fi.Extension.ToLower
                    Case ".fred"
                        ' do something with fred
                    Case ".wilma"
                        ' do something with wilma
                    Case Else
                        ' do something else
                End Select
            End If
        End If
TnTinMN 418 Practically a Master Poster

Zick,

You may need install the ACE provider on the other machine.

Microsoft Access Database Engine 2010 Redistributable

You will need to make sure which bitness (32-64, or both) that your application targets. Go to Project->Properties and select the compile tab.

At the top of the screen you should see two comboboxes.

The one on the left should be "Configuration" and the one on the right should be "Platform". Platform is the one of interest.

Please let us know what is selected for Platform.

TnTinMN 418 Practically a Master Poster

Hi TnTinMN,
I have did as your suggestion, but the error is still there

I was not aware that I made any code suggestions other than point out a pattern that looked like it had faulty logic.

Did you apply your fix to the similar logic used for the "payment" and "results" worksheets?

Please show your new logic.

TnTinMN 418 Practically a Master Poster

Don,

No offense intended, but you need to get more of the basics (no pun intended) under control first.

Learn to use the debugger. It is there for reason it and is your best friend.

Debugging User Interface Reference

Set a break-point in your code and inspect the variable's contents by hovering your mouse pointer over the variable name. This will allow you to see if the variables actually hold what you think they do.

You are using SQL Server, yet your code is using the OLEBD namespace data objects (connection, dataadapter, etc.). This in itself is not incorrect, but there is the SQLClient namespace that has versions of these objects specifically tailored to SQL Server.

Minor issue: you are hard coding your connection strings into your code. This will make it a pain later on when you want to distribute your application. You could define a string variable in Module or my preference is to use the My.Settings collection that VB provides. You can access this by going to Project Properties and selectioning the settings tab. When you define the setting, select "Connection string" for the type.

In the code you have shown, you are "opening" a connection. You should be close every connection you open. I believe the DataAdapter fill method does not require you top open the connection first. It will open and close the connection that you have provided it.

I also suggest that you consider using the DataSet designer to assist you in …

TnTinMN 418 Practically a Master Poster
 xlWorkBook = xlApp.Workbooks.Add
' first worksheet
If xlApp.Application.Sheets.Count() < 1 Then
cmd.CommandText = "Select * From students"
cmd.Connection = connection
da.SelectCommand = cmd
da.Fill(dt)
dgrid.DataSource = dt
location = SaveFileDialog1.FileName
xlWorkSheet = CType(xlWorkBook.Worksheets.Add(), Excel.Worksheet)
xlWorkSheet = xlWorkBook.Sheets("Students")

I believe this statement is your problem: xlWorkSheet = xlWorkBook.Sheets("Students")
Unless your Normal template has a Students worksheet in it, xlWorkSheet will be unassigned (Nothing).

TnTinMN 418 Practically a Master Poster

But when i run the setup to install it in another computer which is a 64bit. My project didnt connect to the database which is access.

The most likely issue is that the target install can not find the DB provider.

If you are using the Jet provider, your application must be 32-bit as there is no 64-bit Jet provider.

If you are using the ACE provider, then make sure you have the correct (32 vs 64) installed to match your application's targeted CPU. see: http://msdn.microsoft.com/en-us/library/ff965871.aspx#DataProgrammingWithAccess2010_using32vs64ace

I believe that if you used the ANYCPU option, then it would JIT to a 64-bit application on a 64-bit OS.

Begginnerdev commented: Yeppers! +8
TnTinMN 418 Practically a Master Poster

I am not going to try and figure out where your logic went wrong, but rather I am going to show you a different way.

Date values are store as Doubles that are referenced to a base value. These values can be either added to or subtracted from and the result converted back to a meaningful values.

Here is the basic logic:

    Dim d1 As Date
    ' assume mm/dd/yyyy date format
    d1 = CDate("1/1/2013 8:05 AM")

    Dim d2 As Date

    d2 = CDate("1/3/2013 6:00:30 PM")

    Dim diff As Double
    diff = d2 - d1

    ' get difference in days
    ' days is the interger part of the number
    Dim diffDays As Integer
    diffDays = Fix(diff)

    ' subtract off the days
    diff = diff - diffDays

    ' get the number of hours
    ' multiply remainder by 24

    diff = diff * 24#

    'the integer part is now the number of hours

    Dim diffHours As Integer
    diffHours = Fix(diff)

    ' subtract off the hours
    diff = diff - diffHours

    ' multiply by 60 to get minutes

    diff = diff * 60#
    Dim diffMinutes As Integer
    diffMinutes = Fix(diff)
    diff = diff - diffMinutes


    ' multiply by 60 to get seconds

    diff = diff * 60
    Dim diffSeconds As Integer
    diffSeconds = Fix(diff)
TnTinMN 418 Practically a Master Poster

Not sure of what use this would be, but for OLEDB connections you could do it like this:

Private Sub Search()
   Dim conn As New OleDb.OleDbConnection("Your Connection String ")
   conn.Open()
   ' get all tables filtered to user tables
   Dim dbTables As DataTable = conn.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "Table"})
   conn.Close()

   For Each tableentry As DataRow In dbTables.Rows
      Dim cmd As New OleDb.OleDbCommand("Select * From [" & tableentry("Table_Name").ToString() & "]", conn)
      Dim da As New OleDb.OleDbDataAdapter(cmd)
      Dim tmpTable As New DataTable
      da.Fill(tmpTable)

      ' get a list of string datatype columns in tmpTable
      Dim cols As List(Of DataColumn) = (From col In tmpTable.Columns _
                                         Select dc = CType(col, DataColumn) _
                                         Where dc.DataType Is GetType(String) _
                                        ).ToList()

      For Each r As DataRow In tmpTable.Rows
         For Each dc As DataColumn In cols
            If r.ItemArray(dc.Ordinal).ToString().Contains("fred") Then
               'found one
               Debug.WriteLine("Table:  " & tableentry("Table_Name").ToString())
               Debug.WriteLine("Column:  " & dc.ColumnName)
               Debug.WriteLine("Value:  " & r.ItemArray(dc.Ordinal).ToString())

            End If
         Next
      Next

   Next
End Sub
TnTinMN 418 Practically a Master Poster

When you override OnMouseDown and do not call the base method, you prevent the OnClick method from being called. Therefore, move the code (this.Checked = !this.Checked;) from OnClick to OnMouseDown.

    protected override void OnMouseDown(MouseEventArgs mevent)
    {
        //base.OnMouseDown(mevent);
        this.Checked = !this.Checked;
    }
TnTinMN 418 Practically a Master Poster

@Jim, right idea, but wrong laguage. This forum is for VB4 through VB6, not VB.Net.

    Dim Lines() As String

    Lines = Split(linereadfromcomm, vbNewLine)

    ' determine number of text items extracted from linereadfromcomm
    ' so that you do not try to reference an array element that does
    ' not exist when assigning values to the textboxes

    Dim numlines As Integer
    numlines = UBound(Lines) + 1
    If numlines > 0 Then Text1.Text = Lines(0)
    If numlines > 1 Then Text2.Text = Lines(1)
    If numlines > 2 Then Text3.Text = Lines(2)
TnTinMN 418 Practically a Master Poster

it seems like you have experience with listviews

Not really, I do not particularly like this control.

n vb 6 you could set the BackgroundImageAligment in .net thats not allowed

Yeh, if you do a search you will find that in the original .Net they had some issues with it. I did some snooping of the source code and for some reason they did not give you the option to set the x,y positioning eventhough there does not appear to be any reason for it. They just locked it into (0,0), the top-left corner. So as usual when the control does not do what you want, you need to create your own version. I had some issues with graphical artifacts when something dragged over the image, so I added some hacks. Its not perfect, but close. It does give you a bit more control on positioning. You set the (x,y) point as an integer percentage value for x and y. You will see the new properties in the property grid. Just add this to your project, build the project and it should show up at the top of your toolbox.

Public Class LV
   Inherits ListView

   <Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True, CharSet:=Runtime.InteropServices.CharSet.Auto)> _
   Private Shared Function SendMessage(ByVal hWnd As IntPtr, _
                                       ByVal Msg As Int32, _
                                       ByVal wParam As IntPtr, _
                                       ByRef lParam As LVBKIMAGE) As IntPtr
   End Function

   Private Structure LVBKIMAGE
      Public ulFlags As LVFlags
      Public hbm As IntPtr
      Public pszImage As String
      Public cchImageMax As Int32
      Public …
TnTinMN 418 Practically a Master Poster

PopulateGridView(.SelectedValue.ToString());

SelectedValue will be a DataRowView and not the Text displayed in the combobox.

Use: ((DataRowView)comboBox1.SelectedValue).Row["TABLE_NAME"].ToString()
or I guess you could just use comboBox1.Text.

Also, it would probably be a good idea to dispose of the datagridview data source before re-assigning it to a new DataTable.

        if (dataGridView1.DataSource != null && dataGridView1.DataSource is DataTable)
        {
            ((DataTable)dataGridView1.DataSource).Dispose();
        }
TnTinMN 418 Practically a Master Poster
TnTinMN 418 Practically a Master Poster

@TnTinMN: after working on your code to make it work another problem is noticed. you can't make a transparent button on the MouseEnter event :( :S.
so it will be noticed as a button and not as a checkbox
I can provide you with pictures it you want

Just override the OnMouseEnter method and do not call the base OnMouseEnter method.

    protected override void OnMouseEnter(EventArgs e)
    {
        //base.OnMouseEnter(e);
    }