Begginnerdev 256 Junior Poster

Many questions have to be answered first.

Is the database local or on a server?
If local, you will just copy the database into the project.
If on server, you will have to connect to the server.

If so, is the server using dns or an ip?
Using the link above, you can write a connection string with an ip or the dns name.

If ip, is it static?
If the server's ip is not static, when the lease is not renewed - the application will break.

Begginnerdev 256 Junior Poster

Here is a link that might help you. It is to a MSDN thread for someone asking the same question.

Begginnerdev 256 Junior Poster

Here is a good forum post to give you an idea.

I hope this helps.

Begginnerdev 256 Junior Poster

Before issueing the update, check to see if the parameters are passing in correctly:

MsgBox(cmd2.CommandText)
cmd2.ExecuteNonQuery
Begginnerdev 256 Junior Poster

Open the access database, and open the table in datasheet view.

Once the table is open, look for the current record you are editing - see if the value that is being pulled in is correct.

Begginnerdev 256 Junior Poster

Have you verified that the number you are putting in the textbox is indeed the correct customer ID from the table?

Begginnerdev 256 Junior Poster

If the CustomerIDTextBox is accessable, that will be the value you need.

If the problem is that the text box is on another form, you can create a Public Property in that form's class and call it from the other form:

Public Class Form1
'....
    Public Property CustomerID as String
        Get
            Return CustomerIDTextBox.Text
        End Get
        Set(value As String)
            CustomerIDTextBox.Text = Value
        End Set
    End Property
End Class

Public Class Form2

    Private Sub btnUpdate.Click(ByVal sender as object, ByVal e as eventargs) Handles btnUpdate.Click
        Try

            Dim cmd2 As OleDBCommand("UPDATE tbl_Customers SET cust_Company=@cust_Company WHERE CustomerID=@CustomerID",conn)
            cmd2.Parameters.AddWithValue("@cust_Company",Cust_CompanyTextBox.Text)
            cmd2.Parameters.AddWithValue("@CustomerID",Form1.CustomerID) 'GETTING THE PROPERTY VALUE

            cmd2.ExecuteNonQuery()
        Catch ex As Exception
              MsgBox(ex.ToString)
        End Try
    End Sub
End Class

I hope this clarifies for you.

When you say tieing it to it, are you wanting to pull in the new values into a dataset?

Begginnerdev 256 Junior Poster

If your table structure looks something like:

customerID|customerCompany|customerLocation
Identity  |    text       |     text

Then when you issue update, it is already tied to the same row.

If the CustomerIDTextBox.Text is the correct value that is.

If you are pulling the values into the form , as you stated earlier, I am assuming you have a select statement?

If so, you can use that ID for the customer ID

Begginnerdev 256 Junior Poster

That is correct, assuming that customer ID is a unique value in that table.

If customer ID appears more than once in that column/ in that table - the statement will update all of those records.

It is always a smart thing to use an identity column or something of the sort.

Begginnerdev 256 Junior Poster

You will need a WHERE clause and a unique value;

For example:

"UPDATE tbl_Customers SET cust_Company=@custCompany WHERE cust_ID = 3"
Begginnerdev 256 Junior Poster

I'm sorry. The correct syntax will be:

"UPDATE tbl_Customers SET cust_Company=@custCompany"

That's what I get for absent mindedly typing responses.

Begginnerdev 256 Junior Poster

You can add the videos to your project as a resource.

My Project > Resources > Add Existing File

This will embed the videos in the project.

Then to reference them, you can do something like My.Resources.ResourceName

Begginnerdev 256 Junior Poster

You just simply need to change your query:

   'SQL Update statements will not have an INTO clause.
   Dim UpdateCommand As New OleDb.OleDbCommand("UPDATE tbl_Customers(cust_Company) VALUES(@custCompany)", con)
Begginnerdev 256 Junior Poster

This looks like it could be a .ini file for a game. Am I correct?

       'THIS ASSUMES THAT THE FILE CONTAINS NOTHING BUT THE {NAME VALUE} FORMAT.
        'Read all lines from the file, parse, and then index them.
        Dim sr As New StreamReader("PathToMyFile")
        Dim lstString As New List(Of List(Of String))

        'We will use a datatable to store your objects.
        Dim dt As New DataTable

        Do While sr.Peek <> -1
            lstString.Add(sr.ReadLine.Split(" ").ToList)
        Loop

        'Now add the first column  of each index to the data table as column names...
        For i = 0 To lstString.Count - 1
            dt.Columns.Add(lstString(i)(0).Replace("""", "")) '0th index will be the NAME object.
        Next

        'Next Load The datatable.
        Dim dr As DataRow = dt.Rows.Add

        For i = 0 To lstString.Count - 1
            'This will pair the values with the column.
            'Example: dr("JoyStick") = 0
            dr(lstString(i)(0).Replace("""", "")) = lstString(i)(1).Replace("""", "")
        Next


        'To get the values now, just type something like this:
        'Data table row 0, column JoyStick
        Dim sJoyStickValue = dt(0)("JoyStick")
Begginnerdev 256 Junior Poster

And it appears that my first copy/paste attempt of the first code snippet is missing the lstString type.

lstString is declared at a List(Of List(Of String))

Dim lstString As List(Of List(Of String))

My appologies.

Begginnerdev 256 Junior Poster

You could split the line using the String.Split function and reference the index of that value.

Example:

        Dim sr as New StreamReader("MyPath")
        Dim da As New OleDbDataAdapter("SELECT * FROM myTable", "MyConnectionString")
        Dim dt As New DataTable

        da.Fill(dt)
        'This will loop until every line is read.
        Do While sr.Peek <> -1
            lstString.Add(sr.ReadLine.Split(",").ToList)
        Loop

        'To reference the values for insert, do something like this:

        'Set index to 1 to skip first row (headers)
        For i = 1 To lstString.Count - 1
            Dim dr As DataRow = dt.Rows.Add

            dr("Column1") = lstString(i)(4) 'Where 4 is the index of the column ***REMEMBER THAT ARRAYS ARE ZERO BASE
            dr("Column2") = lstString(i)(7)
        Next

        da.UpdateCommand = New OleDbCommandBuilder(da).GetUpdateCommand
        da.Update(dt)
Begginnerdev 256 Junior Poster

I am sorry friend, for it seems you have posted in VB.NET.

As for connections, you can find a good reference HERE

I will flag your post for the moderators to move to the correct section so that you will receive the correct help.

Begginnerdev 256 Junior Poster

Just create a DataSet to hold the table in:

Private Function GetTable() As DataSet
    Dim con As New Data.OleDB.OleDBDataAdapter("YourConnectionStringHere")
    Dim da As New Data.OleDB.OleDBDataAdapter(New Data.OleDB.OleDBCommand("SELECT * FROM tbl_Employees",con)
    Dim ds As New DataSet
    Try
        da.Fill(ds,"tbl_Employee")
        'To reference the table, use ds.Tables("tbl_Employee")
        If ds.Tables("tbl_Employee") IsNot Nothing Then Return ds Else Return New DataSet
    Catch ex As Exception
        MsgBox(ex.ToString)
    Finally
        con.Close()
        con = nothing
        da = nothing
    End Try
End Function

As for the array (If absolutely wanted.)

Dim strAr As New List(Of String)
'To Add a new item to the list, do the following...
strAr.Add("MyString")
'As all arrays, the list will be zeroth based. 
'First index will be 0 and so on...
Begginnerdev 256 Junior Poster

I am assuming that you are using a gridview or some kind of data control.

Just create a DataSet/DataAdapter, and don't worry about storing values in row changed, you can simply do something like this:

        'Creating the objects
        Dim da As New OleDbDataAdapter(New OleDbCommand("SELECT * FROM tbl", New OleDbConnection("myConStringHere")))
        Dim ds As New DataSet

        'Filling the data adapter
        da.Fill(ds, "myTable")

        'Binding the datasource
        DataGridView1.DataSource = ds.Tables("myTable")
        'You can auto generate colums
        DataGridView1.AutoGenerateColumns = True


        'To update
        da.UpdateCommand = New OleDbCommandBuilder(da).GetUpdateCommand
        da.Update(ds)

        'This will update ANY changes, not just row by row.
Begginnerdev 256 Junior Poster

After doing a little searching, I can see that you have used the code from bytes.com.

Here is a lengthy post on VBForumns that may be of some use to you.

Begginnerdev 256 Junior Poster

Not sure if this helps (doesn't seem anyone else may have any ideas) but here is a link from code project that may help.

Begginnerdev 256 Junior Poster

I would check your new statements:

Dim ds As New DataSet9.            
Dim apt As New SqlDataAdapter
apt = New SqlDataAdapter(sqlstr, constr)

As these may be looking for parameters that you are not passing in correctly.

My suspicion is on this statement:

apt = New SqlDataAdapter(sqlstr, constr)

I believe you may have your to change your parameters.
After reading the code tag, it looks like the contructor wants:

*New(selectCommandText as String, selectConnectionString as String)*

When you are passing in a string/OLEDB Connection

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

TnTinMN commented: All that just to get to your last sentence? :) +8
Begginnerdev 256 Junior Poster

If you had multiple browser controls, you could thread them. (An example would be tabbed browsing.)

As for one browser control - I am not so sure you can load mutiple pages in one browser.

Here is a nice reference guide for the web browser control.

Begginnerdev 256 Junior Poster

My question is - Is using a custom format on the DateTimePicker out of the question?

Why are you using a MTB over the DTP?

You can set custom DTP formats like so:

DateTimePicker1.CustomFormat = "dd/MM/yyyy"

Or you can set it by using the GUI.

Begginnerdev 256 Junior Poster

Here is a project on CodeProject to do just that.

Begginnerdev 256 Junior Poster

I would say you could represent them with a function shape. ( )

Begginnerdev 256 Junior Poster

A main form with selections could be represented as a decision, or an output.

My guess would be an output because the form does not chose by itself.

Splash -> MDIForm -> Decision
IMHO

Begginnerdev 256 Junior Poster

If the CompanyLogo object is a picturebox or image, you need to do something like this:

If File.Exists(CStr(objDataSet.Tables(0).Rows(0)("LogoPath"))) Then
    If TypeOf CompanyLogo Is PictureBox Then
        CompanyLogo.BackgroundImage = Image.FromFile(CStr(objDataSet.Tables(0).Rows(0)("LogoPath")))
    ElseIf TypeOf CompanyLogo Is Image Then
        CompanyLogo = Image.FromFile(CStr(objDataSet.Tables(0).Rows(0)("LogoPath")))
    Else
        MsgBox("Type not determined")
    End If
Else
    MsgBox("Path not valid/File not found.")
End If
Begginnerdev 256 Junior Poster

Can you please post the code that is throwing the error?

Begginnerdev 256 Junior Poster

Have you tried using SendKeys?

Begginnerdev 256 Junior Poster

Using This you can find a string.

Try something like this in a connect button click:

Try
    Dim con As New OleDBConnection(Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Jet OLEDB:Database Password=" & txtPassword.Text & ";")   'Assuming the password textbox is name txtPassword.
Catch ex As Exception
    MsgBox(ex.ToString())
End Try
Begginnerdev 256 Junior Poster

Here is a HTML parser that I have seen people reference time and time again. Though I have never used it myself, you might find it usefull in this situation.

Begginnerdev 256 Junior Poster

You can reduce the amount of code/debugging you have with something like the following:

Dim lstSheets As New List(Of String)
lstSheets.Add("Students")
lstSheets.Add("Result")
lstSheets.Add("Payment")

Private Sub exportexcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exportexcel.Click
    If xlApp.Sheets.Count <= 3 Then
        For i = 0 To xlApp.Sheets.Count - 1
            'This will do the same as your IF statements.
            SaveInfo(lstSheets(i))
            DeleteCurrent(i)
        Next
    Else
        MsgBox("More sheets exist that are not handled.")
    End If
End Sub

Private Sub SaveInfo(ByVal sCurrent As String)
    Try
        cmd.CommandText = "Select  * From " & sCurrent.ToLower
        cmd.Connection = con
        da.SelectCommand = cmd
        da.Fill(dt)
        dgrid.DataSource = dt
        location = SaveFileDialog1.FileName
        xlWorkSheet = CType(xlWorkBook.Worksheets.Add(), Excel.Worksheet)
        xlWorkSheet = xlWorkBook.Sheets(sCurrent)
        For Each col As DataGridViewColumn In DataGridView1.Columns
            xlWorkSheet.Cells(1, col.Index + 1) = col.HeaderText
            For Each rowa As DataGridViewRow In DataGridView1.Rows
                xlWorkSheet.Cells(rowa.Index + 2, col.Index + 1) = rowa.Cells(col.Index).Value
            Next
        Next
        chartRange = xlWorkSheet.Range("A1", "Z1")
        xlWorkSheet.SaveAs(location)
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Private Sub DeleteCurrent(ByVal sCurrent as String)
    Try
        del_command.CommandText = "Delete From " & sCurrent
        del_command.ExecuteNonQuery()
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub    
Begginnerdev 256 Junior Poster

Have you stepped through the code to find out which sheet/row/cell/line of code the error is being thrown on?

Something that will give us a clue as to where the exception is being thrown?

Begginnerdev 256 Junior Poster

Do you receive any errors while trying to run the application?

It could be a number of things:

ie...
1).NET Framework
2)A DLL the project is compiled with has to be registered
3)You could have a problem with the variables that are 32bit dependant.

I hope these help hunt down the problem!

Begginnerdev 256 Junior Poster

You can try something like this:

Public Sub Node_Handler(ByVal sender As Object, ByVal e As TreeNodeMouseClickEventArgs) Handles SideMenu.NodeMouseClick
    Try
        If e.Node.IsExpanded Then
            MsgBox("Node will close")
            'Your code here.
        Else
            MsgBox("Node will open")
            'Your Code here.
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub
Begginnerdev 256 Junior Poster

You can try to force the software to use 32 bit datatypes with a statement like this.

Try
    '...Your Code.
    Dim shortVal As Short 'Replace this with your short variable.
    Dim i32Converted As Int32 = Convert.ToInt32(shortVal) 'Commit the 32bit value to the database.
    '...Your Code to update database.
Catch ex As Exception
    MsgBox(ex.toString)
End Try
Begginnerdev 256 Junior Poster

That example is actually SQL, and C# is a .Net Language.

The problem exists on querying each table.

If you have a DataSet with each table strongly typed you can try a For Each loop.

Either way, there is no single line statement to solve the problem.

Begginnerdev 256 Junior Poster

You have to update the datasource of the datagrid view.

A DataAdapter will do the job:

Dim da As OleDB.OleDBDataAdapter(New OleDB.OleDBCommand("SELECT * FROM TabelName",MyDbConnection)) 'Make sure the connection passed in is open.
da.UpdateCommand = New OleDBCommandBuilder(da).GetUpdateCommand()' If not you will have to open the connection before calling this line.
da.Update(MyDataGridViewSource) 'Where MyDataGridViewSource is a DataSet
Begginnerdev 256 Junior Poster

This will be an extremely complex thing to do it VB.NET, but here is an example for SQL Server (Syntaticly Close to Access)

Begginnerdev 256 Junior Poster

If the items that are in the access database combobox are infact in a table, then yes.

If not, you will need to create a table, drop the data in, bind the data, and fill the combobox.

Here is an example of DataBinding to help you understand the concept.

Begginnerdev 256 Junior Poster

I honestly hope you don't think some one is going to help with a Spam bot.

Begginnerdev 256 Junior Poster

You can also try using a Masked Text Box.

Begginnerdev 256 Junior Poster

If you are using a Query to fill that report (99.99% sure you are at some point) I would check that Query for parameters than need to be passed in.

Here is an example.

Begginnerdev 256 Junior Poster

Do you have code that draws the chart, or are you using some kind of office interopt to draw it?

Begginnerdev 256 Junior Poster

If you are loading the pages into a hidden web browser control, you can make use of the DocumentCompleted Event.

Begginnerdev 256 Junior Poster

Do you have code that fires on exit click?

If so: I would start there.
Step through the code and see where it stops.

If not: I would start with Cleaning/Rebuilding the Solution.
Build > Clean
Build > Rebuild

It has worked for me a few times.

Begginnerdev 256 Junior Poster
Begginnerdev 256 Junior Poster

You can do as Jim has said and shave a VERY small amount of time off by placing everything inside of the If statement:

If MsgBox("Do you want to Delete?", MsgBoxStyle.YesNo, "Confirm") = MsgBoxResult.Yes Then
    Dim cmd As new OleDBCommand("",con)
    cmd.CommandText = "DELETE FROM [" & EBU2DB_LOB & "] " _
            & " WHERE Brand  = ? " _
            & "   AND LOB    = ? " _
            & "   AND Months = ? "
    cmd.Parameters.AddWithValue("@Brand ", Form_Month_End_Report.Combo_LOB_Brand.Text)
    cmd.Parameters.AddWithValue("@LOB   ", Form_Month_End_Report.Combo_LOB_LOB.Text)
    cmd.Parameters.AddWithValue("@Months", Form_Month_End_Report.Combo_LOB_Month.Text)
    If con.State = ConnectionState.Closed Then con.Open()
    cmd.ExecuteNonQuery()
End If

This will only create the command and set the command text when you want to delete the item.

Reverend Jim commented: Also yep! +12
Begginnerdev 256 Junior Poster

Upon resizing an anchored combobox - I noticed the text was always selected.
This sparked the initiative to fix this problem. (Microsoft decided not to)

So by extending the combobox class we can fix this.

The following class can be dropped into a form for designer manipulation or as a user control.

This is an extremely simple fix.

TnTinMN commented: So I'm not the only one to find that iirritating! That dang edit control box! textbox control! +7
JorgeM commented: nice. +12