Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all 27186 articles
Browse latest View live

VS 2012 Add new, Modify record MSACCESS using ADO recordset

$
0
0
I tried the below code,
1) Button3_Click()...For add new record, there is no error message but no record is added to database

2) Button2_Click()...For update record a error message is shown "Could not load type 'ADODB.FieldsToInternalFieldsMarshaler' from assembly 'WindowsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."

Could somebody help in this.

Code:

Public Class Form1



Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    'update 1st record
    Dim rs As New ADODB.Recordset

    Dim cn As New ADODB.Connection()
    cn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=Test.mdb;"
    cn.Open()

    rs.Open("SELECT * FROM Users", cn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockBatchOptimistic)


    rs.MoveFirst()
    rs.Fields("EmpName").Value = "AAAAA"
    rs.Fields("EmpId").Value = "222"
    rs.UpdateBatch()

    rs.Close()
    cn.Close()
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    'add new Record

    Dim rs As New ADODB.Recordset

    Dim cn As New ADODB.Connection()
    cn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=Test.mdb;"
    cn.Open()

    rs.Open("SELECT * FROM Users", cn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockBatchOptimistic)

    Dim fieldsArray(1) As Object
    fieldsArray(0) = "EmpName"
    fieldsArray(1) = "EmpId"
    Dim values(1) As Object
    values(0) = "4"
    values(1) = "as"

    rs.AddNew(fieldsArray, values)
    rs.UpdateBatch()

    rs.Close()
    cn.Close()
End Sub


Remove Duplicate Values in DatagridView

$
0
0
Hi experts,

how can i Remove duplicate value on my Datagridview.

Please attach image.
Name:  Screen.png
Views: 19
Size:  7.2 KB

And please see my code in populating my Datagrid.

Code:

Dim con As New SqlConnection(sqlcon)
        Try
            con.Open()
            Dim cmd As SqlCommand = con.CreateCommand
            cmd.CommandText = "usp_GetUserBookiList"
            cmd.CommandType = CommandType.StoredProcedure
            Dim dr As SqlDataReader = cmd.ExecuteReader
            Dim dt As New DataTable
            dt.Load(dr)

            If dt.Rows.Count > 0 Then

                For i As Integer = 0 To dt.Rows.Count - 1
                    TableLayoutPanel1.ColumnCount = dt.Rows.Count
                    Dim dgview As New DataGridView
                    With dgview
                        .Dock = DockStyle.Fill
                        .AllowUserToOrderColumns = False
                        TableLayoutPanel1.Controls.Add(dgview)
                        .BorderStyle = BorderStyle.FixedSingle
                        .ColumnCount = 1
                        ApplyGridStyle(dgview, False, False)
                        .Columns(0).HeaderText = Nothing
                        .Columns(0).HeaderText = dt.Rows(i).Item("name").ToString
                        For x As Integer = 0 To dt.Columns.Count - 2
                            For Each Row As DataRow In dt.Rows
                                .Rows.Add(dt.Rows(i).Item(x))

                            Next

                        Next

                        .MultiSelect = True
                        .AllowDrop = True
                        .BackgroundColor = Color.White
                        .Height = 790
                    End With
                Next
            End If
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.Message & vbNewLine & "Error in Populating User.")
        Finally
            If con IsNot Nothing Then
                con.Close()
                con.Dispose()
            End If
        End Try

Can anyone point me to the right direction.

Thanks.
Attached Images
 

VS 2013 Check if item added / removed ListView

$
0
0
Hi,

I would like to know if an item is added / removed from a ListView.
How do I do this?

Thanks in advance

Microsoft.Office.Interop.Outlook.Recipients and removing duplicates

$
0
0
I have the following code set up to make sure that 3 people get emailed, but it checks to see if their names are already included as recipients before sending the email so they don't get it twice.

Would the following code work? Or is there a better solution, such as removing duplicates? If so, how would I do that?

Code:

        Try 'Removes default recipients before adding them again to prevent duplicate mail

            Recipients.Remove(defaultRecipient)
            Recipients.Remove(defaultRecipient2)
            Recipients.Remove(defaultRecipient3)

        Catch ex As Exception

        End Try




        Recipients.Add(defaultRecipient)
        Recipients.Add(defaultRecipient2)
        Recipients.Add(defaultRecipient3)

problem to find right serialport

$
0
0
Hi, i've an application that comunicate with a RS232 device(usb with ftdi chip); it's possible to find the device when connected and get the correct port name? ftdi inf is customizable.

VS 2013 [RESOLVED] Where is VB.NET's start bar shortcut EXE stored?

$
0
0
My Start button on desktop is corrupt for the time being, and there is no way to start my VB.NET.
I can access File Explorer, so I'd like to copy a shortcut onto the desktop, as a band aid for now.
Where is the VB.EXE stored on the C:\ ? so I can make a shortcut to it ?

VS 2015 Label text appearing before progress bar finished

$
0
0
Hi Last time I was here was back in 2002! Still waiting for an answer to that question :rolleyes: LOL
Anyway I've started to code again and I have a problem with the code below.
I want the progress bar to reach the end before showing the Label text.

Code:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim days() As String = {"Today is your lucky day", "Beware of strangers", "Love is in the air",
            "Better stay in today", "You will make a lot of money", "You will get a present", "Something unexpected will happen"}

        Dim number As Integer
        Randomize()
        number = Int(Rnd() * 7)

        If pgb_fortune.Value >= pgb_fortune.Maximum Then
            pgb_fortune.Value = pgb_fortune.Minimum
            lbl_Fortune.Text = "? ? ?"
        Else
            pgb_fortune.Increment(2)
            If pgb_fortune.Value >= pgb_fortune.Maximum Then
                pgb_fortune.Value = pgb_fortune.Maximum
                Timer1.Enabled = False
                If Timer1.Enabled = False Then
                    lbl_Fortune.Text = days(number)
                End If
            End If
        End If

    End Sub
End Class

VS 2013 [RESOLVED] How to SMTP relay to external email address using Office365

$
0
0
I was using my own SBS2008 box with Exchange to relay email. I moved to Office365 and found it's understandably more restrictive. I can modify the SMTP server and if I use authentication I can send to my email address but if I try to send to an external email it fails. I've been reading the Office365 documentation and it's not entirely clear to me how to make this work but they do say it can be done. So my first question is if anyone knows how to do this please let me know what the proper method is.

One non-MS article I read said I will be able to relay to an external address is I use TLS. I'm not familiar with this but I did some research and found that I need to enable SSL and set the port to 587. So I tried the code below but it claims it can not find the server. Does anyone have an idea what I'm doing wrong? I tried to remove the port 587 by using the overload which only specifies the server address but then I got {"Mailbox unavailable. The server response was: 5.7.64 TenantAttribution; Relay Access Denied"}
vb.net Code:
  1. Private Sub Button1_Click() Handles Button1.Click
  2.     Dim mmMessage As New Mail.MailMessage("cory@mydomain.com", "cory@mydomain.com", "Test", "Please ignore and delete")
  3.     Dim objSender As New Mail.SmtpClient("mydomain-com.mail.protection.outlook.com", 587)
  4.     With objSender
  5.         .Credentials = New NetworkCredential("cory@mydomain.com", "MyPassword")
  6.         .EnableSsl = True
  7.         .Send(mmMessage)
  8.     End With
  9.     objSender.Dispose()
  10. End Sub
Thank you for taking the time to read my post.

VS 2015 Json Deserialization

$
0
0
I am trying to deserialize a Json string into an object instance, but am getting the following:

type is an interface or abstract class and cannot be instantated

Here are some dummy classes:
vb.net Code:
  1. <Serializable()>
  2. <JsonObject(MemberSerialization:=MemberSerialization.OptIn)>
  3. Public Class BigWheel
  4.  
  5.     Inherits Bike
  6.  
  7.     <JsonProperty(PropertyName:="Brand")>
  8.     Public Property Brand As String
  9.  
  10.     <JsonProperty(PropertyName:="IsElectric")>
  11.     Public Overrides Property IsElectric As Boolean = False
  12.  
  13. End Class
  14.  
  15. <Serializable()>
  16. <JsonObject(MemberSerialization:=MemberSerialization.OptIn)>
  17. Public Class Motorcycle
  18.  
  19.     Inherits Bike
  20.  
  21.     <JsonProperty(PropertyName:="MPG")>
  22.     Public Property MPG As Integer
  23.  
  24.     <JsonProperty(PropertyName:="IsElectric")>
  25.     Public Overrides Property IsElectric As Boolean = True
  26.  
  27. End Class
  28.  
  29. <Serializable()>
  30. <JsonObject(MemberSerialization:=MemberSerialization.OptIn)>
  31. Public MustInherit Class Bike
  32.  
  33.     <JsonProperty(PropertyName:="Owners")>
  34.     Public Property Owners As New List(Of String)
  35.  
  36.     <JsonProperty(PropertyName:="Wheels")>
  37.     Public Property Wheels As Integer
  38.  
  39.     <JsonProperty(PropertyName:="Color")>
  40.     Public Property Color As Color
  41.  
  42.     <JsonProperty(PropertyName:="IsElectric")>
  43.     Public Overridable Property IsElectric As Boolean
  44.  
  45. End Class
  46.  
  47. Public Class Shop
  48.  
  49.     <JsonProperty(PropertyName:="Products")>
  50.     <JsonConverter(GetType(ConcreteTypeConverter(Of List(Of Bike))))>
  51.     Public Property Products As New List(Of Bike)
  52.  
  53.     ''' <summary>
  54.     ''' Converts the specified Json value into a virtual form object.
  55.     ''' </summary>
  56.     Public Shared Function [New](ByVal JsonValue As String) As Shop
  57.         Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of Shop)(JsonValue)
  58.     End Function
  59.  
  60.     ''' <summary>
  61.     ''' Gets the Json representation of the virtual form object.
  62.     ''' </summary>
  63.     Public Function ToJson() As String
  64.  
  65.         Try
  66.  
  67.             'return the json
  68.             Return Newtonsoft.Json.JsonConvert.SerializeObject(Me)
  69.  
  70.         Catch ex As Exception
  71.  
  72.             'throw exception on error
  73.             Throw
  74.  
  75.         End Try
  76.  
  77.     End Function
  78.  
  79. End Class
  80.  
  81. Public Class ConcreteTypeConverter(Of T)
  82.     Inherits JsonConverter
  83.     Public Overrides Function CanConvert(objectType As Type) As Boolean
  84.         Return True
  85.     End Function
  86.  
  87.     Public Overrides Function ReadJson(reader As JsonReader, objectType As Type, existingValue As Object, serializer As JsonSerializer) As Object
  88.         Return serializer.Deserialize(Of T)(reader)
  89.     End Function
  90.  
  91.     Public Overrides Sub WriteJson(writer As JsonWriter, value As Object, serializer As JsonSerializer)
  92.         serializer.Serialize(writer, value)
  93.     End Sub
  94. End Class

Here is the calling code:

vb.net Code:
  1. Try
  2.  
  3.             Dim store As New Shop
  4.             Dim m As New Motorcycle
  5.  
  6.             'set properties
  7.             m.MPG = 25
  8.             m.Color = Color.Red
  9.             m.Owners.Add("Tom")
  10.  
  11.             store.Products.Add(m)
  12.  
  13.             Dim sJson As String = store.ToJson
  14.  
  15.             Dim store2 As Shop = Shop.[New](sJson)
  16.  
  17.             Stop
  18.  
  19.         Catch ex As Exception
  20.             Stop
  21.  
  22.         End Try

Need to import:

vb.net Code:
  1. Imports Newtonsoft.Json

I have read about this, but am still having trouble trying to figure out how to fix. Any help?

auto format DVD on insert with visual basic

$
0
0
hi
I'm trying to automatically format a blank dvd on insert.
I have autoplay setup so when i insert a blank dvd the "burn a disc" window opens.
I want to be able to format with date as disc title and choose the option "Like a USB flash Drive"

I've seen Nero incd but it wont run on windows 8.1.

I've tried sendkeys but i cant seem to select the windows host process rundll32 window.

Any ideas on how i could code this?
many thanks in advance.

Create new Outlook calendar via vb.net

$
0
0
Hi all,

I'm trying to create a way my end user can create a new Outlook calendar via vb.net, a shared one...but I can't figure out how to get this working.
I found a numerous tutorials on how to create new appointments...but not really how to create a calendar?

Can somebody help me or show me the way to the solution?

Thanks in advance.

Floating textbox hover over datagridview

$
0
0
I have a floating from that displays a large textbox that when the user hovers the mouse over a cell in the datagridview it display the contents of the cell text in a floating form.

The floating form doesn't show on the first cell in the column I hover over, but if I move the mouse up of down it then shows the contents!

Now the code works and it does the job, but can it be written a bit more elegantly and shorter than what I have.

I test a lot of conditions before showing the form and

Code:

Private Sub DataGridView1_CellMouseEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellMouseEnter
        NewRow = e.RowIndex
        If NewRow <> PrvsRow Then
            If bFrmShown Then
                FrmViewText.Close()
                FrmShown = False
            End If
            If e.RowIndex > -1 And e.ColumnIndex = 1 Then
                Dim RowHeight1 As Integer = DataGridView1.Rows(e.RowIndex).Height
                Dim CellRectangle1 As Rectangle = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False)
                CellRectangle1.X += DataGridView1.Top + RowHeight1
                CellRectangle1.Y += DataGridView1.Left
                DisplayPoint1 = PointToScreen(New Point(CellRectangle1.X, CellRectangle1.Y))

                If Not IsDBNull(DataGridView1.Rows(e.RowIndex).Cells(1).Value) Then
                    TestStr = DataGridView1.Rows(e.RowIndex).Cells(1).Value ' x & "  " & y
                Else
                    TestStr = ""
                End If
                If Not (FrmViewText.Visible) Then
                    bFrmShown = True
                    x = CellRectangle1.X
                    y = CellRectangle1.Y
                    FrmViewText.Show()
                End If
              End If
        End If
        If e.ColumnIndex <> 1 Or e.RowIndex >= MaxRows Then

            If (FrmViewText.Visible) Then
                FrmShown = False
                FrmViewText.Close()
            End If
        End If
        PrvsRow = e.RowIndex
    End Sub

Any advice appreciated!

Visual Studio 2015

$
0
0
It says license only 3 days left need to sign in
but i can't sign in my account it says some SP: error

VS 2015 Networking TCP Client Read

$
0
0
Hi All

Thanks for taking the time to read this.

I am just going to ask the question so I don't keep trying to do something the wrong way.
I am writing a program to Talk to a serial device. No Problems here thanks to some good users on here
now I'm trying to get to to work on a serial to ethernet adapter.

Now for the question sending data has been pretty plan sailing but receiving data is a different story.
I am hoping I can just send and receive as I would a serial device

What I am getting back is a stream of random lengths or it just seems random where at the end of the data is just a heap of bytes at the end of the message. Which is making it hard to find the bytes in the buffer I need

I was hoping to use GetStream.Read after every Client.Send Command.

Is this the wrong way of doing this?

Thanks in Advance

control multiple listbox from one button

$
0
0
hello!
i have 3 listbox on my form.
i want to update or delete or add some value into these all 3 listbox.
to update ,delete , add value i need to make each button per listbox.
but is it possible to update ,delete, add value by using one textbox and button?
i searched google much but unfortunetly difficult found solution.
any help much appreciate!

Name:  save.jpg
Views: 32
Size:  18.7 KB
Attached Images
 

VS 2010 VBA - Excel:If value What parameter in Find(What:=“value”) doesn't exist ,for all IDs

$
0
0
I have a problem with VBA for Excel.

I want to search for a specific value(for a specific ID) in a column of a sheet and pass the value in another table row (of that ID). What happens If the value in the What:="value" parameter of the Find() method doesn't exists for all the IDs in the column?

If the ID (of the first sheet) doesn't have that value I dont want to pass any value to the other sheet (of that ID).I want to set a "#N/A" value instead. In fact it passes the value of the predecessor ID.

What should I do?:confused:

RemoveAt Throwing off Index for ListOf?

$
0
0
I've got a ListOf Strings I capture (USB data). I'd like to discard the first one, as it's meaningless in my application. I use the RemoveAt(0) method, but later when I try to do a For Each Item I get an error because the last Item index is too high by 1. What am I missing? Shouldn't RemoveAt take care of the index?

Code:

USBData.PacketData.RemoveAt(0)

'Do some other stuff in a different form, then go back and write the packet data to a txt file

        For Each Item In USBResource.USBData.PacketData
            OutFile.WriteLine(USBResource.USBData.PacketData(Item))
        Next

I'm sure I'm missing something because of the zero index, but I can't see what...

Can you pass object names when overloading a function?

$
0
0
I'd like to make a function where I can cause a checkbox being checked to disable a control on a form by simply going:

disablebox(Textbox1, Checkbox1)

The code would be loaded into the form change event.

Would this work? If not, could it be modified to work?

Code:

    Public Function disablebox(ByVal dimMe As Object, ByVal dimCheckbox As Object)


        If dimCheckbox.checked = True Then

            dimMe.enabled = False

        Else

            dimMe.enabled = True
        End If

    End Function

I am getting System.Int32 Error! Please Help

$
0
0
Code:

        Dim number(9) As Integer

                    Randomize()
                    ' The program will generate a number from 1 to 10
                    number(i) = Int(Rnd() * 10) + 1

                    Console.WriteLine(number)

                    ASCnumber(i) = Asc(number(i))

                    Console.WriteLine(ASCnumber(i))

                Next

When running this i get system.Int32 error in console! I do not know what to do or why it is happening. This is in a loop also if that helps

please assist

thanks

Index on textbox

$
0
0
I want to modify the interface of former software, but I found they use different functions of textbox. It seems they use the textbox as array, and when check the proprieties of textbox I found it has a propriety named "index on textbox" . But when I use the textbox by myself, I never found it has a propriety named "index on textbox", so how to figure out this?
Viewing all 27186 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>