|
That is irrelevant. If the floating point number represents a value greater than 2147483647, then you will get an overflow error. you need to inspect your data values to see why it is happening; we cannot do that.
|
|
|
|
|
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
dataFile = "C:\Users\achikanya\Desktop\xray database.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String
str = "Insert into Patient Details([National ID],[First Name],[Last Name],[Phone number],[Email],[Procedure],[Gender],[Address],[Date]) Values (?????????))"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
cmd.Parameters.Add(New OleDbParameter("National ID", CType(TextBox1.Text, String)))
cmd.Parameters.Add(New OleDbParameter("First Name", CType(TextBox2.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Last Name", CType(TextBox3.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Phone number", CType(TextBox4.Text, String)))
cmd.Parameters.Add(New OleDbParameter("(Email", CType(TextBox5.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Procedure", CType(TextBox6.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Gender", CType(TextBox7.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Address", CType(TextBox8.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Date", CType(TextBox9.Text, String)))
|
|
|
|
|
You're missing commas between the parameter placeholders, and you've got an extra closing bracket at the end of the statement:
str = "Insert into Patient Details([National ID],[First Name],[Last Name],[Phone number],[Email],[Procedure],[Gender],[Address],[Date]) Values (?, ?, ?, ?, ?, ?, ?, ?, ?)"
There's also no need to CType the Text properties as String , since they're already String s.
cmd.Parameters.Add(New OleDbParameter("National ID", TextBox1.Text))
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In addition to Richard D's comments, you have an open parenthesis character before "Email" in the following:
cmd.Parameters.Add(New OleDbParameter("(Email", CType(TextBox5.Text, String)))
|
|
|
|
|
hola buenas tardes:
espero puedan ayudarme con la siguiente duda, tengo conexion a un lector de huella iface 302
el cual necesito extraer (al momento de checar, el id y nombre del usuario )
alguna sugerencia
esto en el evento onattransction.
Dim enrollnumber As String
If CZKEM1.ReadAllUserID(CInt(MachineNumber)) Then
GetUserTmpExStr MachineNumber, dwenrollnumber, dwFingerIndex, iFlag, tmpData, tmpLength
dwEnrollNumber1 = dwEnrollNmber
dwEnrollNumber1 = EnrollNmber
'Wend
End If
Text4.Text = UserID
Text1.Text = EnrollNmber
Else
'MsgBox "Verify Fail"
End If
no logro ..ayuda.
|
|
|
|
|
|
using vb.net windows form to create custom error message box
modified 9-Oct-18 10:41am.
|
|
|
|
|
What is your user interface web, winforms, WPF. They are all very different.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I did this once with an array in the tag. on the form activate I read the array and returned on the click the dialog result
another way is create propertys
Private _buttonPushed As Integer
Private _buttonarray(,) As Integer
Public WriteOnly Property buttons(buttonarray(,) As String)
Set(value)
buttonarray = buttonarray
End Set
End Property
Public ReadOnly Property Result() As Integer
Get
Return _buttonPushed
End Get
End Property
ButtonArray contains in this case Texts and values
|
|
|
|
|
Hi all,
I am a very beginner in programming, myself learned something out of curiosity from internet.
After more than a year work, I had developed a program in vb 2010 express for the data entry of my patients details in my clinic. Now I need to do something to add the contact details of patient to my google contacts. Currently I am saving the details to an excel sheet and importing it to google manually. After searching in the internet, I had read it needs API and its not free to use also. I had never worked with API and is thinking of a free option. Any one can help me in this matter? Thanks in advance.
|
|
|
|
|
|
Thanks for the reply. Will check it out.
|
|
|
|
|
Could someone tell me how to create a random access file in visual basic.net? I know how to do it in vb6 but I think it is different in vb.net Any help would be appreciated.
Jeff
|
|
|
|
|
|
Sorry again guys,
After working for an hour or so I finally figured out that GetString() is also
including the terminating Null char (0) in the string so
sReturn = System.Text.Encoding.UTF8.GetString(buf, 0, buf.length-1)
works.
I have code that uses System.Text.Encoding to convert a byte() to string.
I use Marshal.Copy(lpEntryBuffer, buf, 0, Len) to copy lpEntryBuffer to buf.
I have created test code below that shows what is being copied into buf above
getting the same result.
' buf Text = "1, 0, 0, 1"
Dim buf() As Byte = {49, 44, 32, 48, 44, 32, 48, 44, 32, 49, 0}
Dim sReturn as String = System.Text.Encoding.UTF8.GetString(buf)
' This test is False, not equal
If sReturn = "1, 0, 0, 1" Then
sReturn = ""
End If
The value of sReturn in stack trace looks like this:
"1, 0, 0, 1
without the end double quote which seems like a string termination problem.
Can someone help me?
Thank you
-- modified 3-Oct-18 18:37pm.
|
|
|
|
|
--edit
Didn't see the "already solved" part
From the code you shown;
Sub Main()
Const DEFAULTTEXT As String = "1, 0, 0, 1"
Dim buf() As Byte = {49, 44, 32, 48, 44, 32, 48, 44, 32, 49, 0}
Dim sReturn As String = System.Text.Encoding.UTF8.GetString(buf)
If DEFAULTTEXT = sReturn Then
sReturn = ""
End If
If DEFAULTTEXT.CompareTo(sReturn) = 0 Then
sReturn = "equal to default"
End If
Console.WriteLine(sReturn)
Console.ReadLine()
End Sub
Outputs 1, 0, 0, 1
There's no quotes, because they aren't in the string. The Bytebuf starts with ascii 49, which means "1". 44 is a comma, 32 a space.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
modified 4-Oct-18 8:36am.
|
|
|
|
|
I am trying to simulate the isdirty feature from Access. I want to check and see if anything has changed so I can prompt the user to save their work or lose it. So far I have written a subroutine that backs up the data in the form. But I am having problems with the code for the compare when they try and exit. So how do I compare the data I stored in the dataset with what is on the form?
Imports System.Data.SqlClient
Public Class Form1
Dim dsShiftLog As DataSet = New DataSet("ShiftLog")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Shift_PrintersTableAdapter.Fill(Me.LazerMaintenanceDataSet.Shift_Printers)
Me.Shift_LogTableAdapter.Fill(Me.LazerMaintenanceDataSet.Shift_Log)
Backup_data(tbShift_Key.Text)
End sub
Private Sub Backup_data(ShiftKey As Integer)
Dim table1 As DataTable = New DataTable("shiftlog")
Dim strSql As String = "SELECT * FROM Shift_Log WHERE Shift_Log.Shift_Key = '" & ShiftKey & "';"
'Dim dtb As New DataTable
Using SqlConn As New SqlConnection(My.Settings.LazerMaintenanceConnectionString)
SqlConn.Open()
Using da As New SqlDataAdapter(strSql, SqlConn)
da.Fill(table1)
End Using
SqlConn.Close()
End Using
Dim table2 As DataTable = New DataTable("shiftprinters")
strSql = "SELECT * FROM Shift_Printers WHERE Shift_Printers.Shift_Key = '" & ShiftKey & "';"
'Dim dtb As New DataTable
Using SqlConn As New SqlConnection(My.Settings.LazerMaintenanceConnectionString)
SqlConn.Open()
Using da2 As New SqlDataAdapter(strSql, SqlConn)
da2.Fill(table2)
End Using
SqlConn.Close()
End Using
dsShiftLog.Tables.Add(table1)
dsShiftLog.Tables.Add(table2)
End Sub
|
|
|
|
|
Comparing the data would require a copy of said data and probably a lot of time.
Take the isdirty flag from notepad, as a simpeler example. If the user presses a key in that textbox (keydown), a boolean called "isDirty" is set to true - meaning the user edited the text, and now needs saving. Notepad doesn't compare the text to the old one; it merely checks if the user edited.
You can do the same; when loading from Access (or whatever), set a bool "isDirty" to false on load, and make it dirty on keypress.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
wjburke2 wrote: Dim strSql As String = "SELECT * FROM Shift_Log WHERE Shift_Log.Shift_Key = '" & ShiftKey & "';"
Don't do it like that!
Using string concatenation to create a SQL query leads to SQL Injection[^] vulnerabilities.
In this particular case, since the ShiftKey is an Integer , the query is OK. But it's a bad habit to get into, and there's nothing in your code to remind you to switch to using parameters if you ever change the method parameter to be a String .
You're also relying on VB's implicit type coercion to convert the text entered by the user into an Integer . That's going to be prone to throwing exceptions when the user mis-types the key. You should use Integer.TryParse[^] to attempt to convert the text, and display a message to the user if the conversion fails.
You don't need to explicitly open and close the connection; the data adapter will do that for you. It will also allow you to load both tables with a single command:
DataAdapter DataTable and DataColumn Mappings | Microsoft Docs[^]
Private Sub Backup_data(ByVal ShiftKey As Integer)
Const strSql As String = "SELECT * FROM Shift_Log WHERE Shift_Key = @ShiftKey; SELECT * FROM Shift_Printers WHERE Shift_Key = @ShiftKey";
Using SqlConn As New SqlConnection(My.Settings.LazerMaintenanceConnectionString)
Using da As New SqlDataAdapter(strSql, SqlConn)
da.SelectCommand.Parameters.AddWithValue("@ShiftKey", ShiftKey)
da.TableMappings.Add("Table", "shiftLog")
da.TableMappings.Add("Table1", "shiftprinters")
da.Fill(dsShiftLog)
End Using
End Using
End Sub
...
Dim ShiftKey As Integer
If Integer.TryParse(tbShift_Key.Text, ShiftKey) Then
Backup_data(ShiftKey)
Else
End If
Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
How you are binding your DataSet to controls? Are you using BindingSource ?
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
Hello, I still use VB.Net once. I have a college project assignment to make cryptography. but I have experienced an error in the program. Please help me.
***program code that displays an error
'Pembentukan Kunci
Public Sub GetIDEAKey(ByVal pstrKey As String)
Dim strKunci As String = ""
Dim nRound = 1, nKey As Integer = 0
'Dim K(9, 6) As String
'Dim KD(9, 6) As String
Dim i As Integer
Dim j As Integer
'Biner kunci - 128 bit
strKunci = StringtoBinary(pstrKey)
'---- Pembentukan Key Enkripsi ----
For i = 1 To 7
'Kelompokkan ke 8 buah subkey (pjg 16 bit)
For j = 1 To 128 Step 16
'Tambah nKey
nKey = nKey + 1
If nKey = 7 Then
'Tambah Round
nRound = nRound + 1
'Reset nilai nKey
nKey = 1
End If
If (nRound & nKey) < 95 Then
'Kunci per round
KE(nRound - 1, nKey - 1) = strKunci.Substring(j - 1, j - 1 +16)***
End If
Next
'Untuk putaran terakhir tidak usah rotasi kiri
If i <> 7 Then
strKunci = FRotateLeftShift(strKunci, 25)
End If
Next
|
|
|
|
|
Assuming the line marked with "***" is the one that throws the error:
strKunci.Substring(j - 1, j - 1 +16)
Either:
(j - 1) is greater than or equal to the length of strKunci ; or(j - 1) + (j - 1 + 16) is greater than or equal to the length of strKunci
NB: The second parameter to Substring is the length of the substring you want, not the index of the end of the substring. I suspect you probably meant:
strKunci.Substring(j - 1, 16) This will still throw an exception if (j - 1) + 16 is greater than or equal to the length of the string.
String.Substring Method (System) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I use for some years this code that worked.
Public Class HotKey
' Windows API functions and constants
Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Short
Private Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As Short) As Short
<pre>
Public Const MOD_ALT As Integer = 1
Public Const MOD_CONTROL As Integer = 2
Public Const MOD_SHIFT As Integer = 4
Public Const MOD_WIN As Integer = 8
Private f As Form
Public Enum EKeyModifier
Neutral
Alt
Control
Control_Alt
Shift
Shift_Alt
Shift_Control
Shift_Alt_Control
Windows
Win_Alt
Win_Control
Win_Control_Alt
Win_Shift
Win_Shift_Alt
Win_Shift_Control
Win_Shift_Alt_Control
Norepeat = &H4000
End Enum
Private _Modifier As EKeyModifier
Private _Key As System.Windows.Forms.Keys ' the id for the hotkey
Dim hotkeyID As Short
Sub SDummy()
MsgBox("Dummy routine ShortKey")
End Sub
Public Property Key() As System.Windows.Forms.Keys
Get
Return _Key
End Get
Set(ByVal value As System.Windows.Forms.Keys)
UnregisterGlobalHotKey()
RegisterGlobalHotKey(value, _Modifier, f)
_Key = value
End Set
End Property
Public Property Modifier() As EKeyModifier
Get
Return _Modifier
End Get
Set(ByVal value As EKeyModifier)
UnregisterGlobalHotKey()
RegisterGlobalHotKey(_Key, value, f)
_Modifier = value
End Set
End Property
' register a global hot key
Function RegisterGlobalHotKey(ByVal hotkey As EKeyModifier, ByVal modifiers As Integer, ByVal frm As Form) As Boolean
Try
f = frm
' use the GlobalAddAtom API to get a unique ID (as suggested by MSDN docs)
'adapted code(obsolete)
'Dim atomName As String = AppDomain.GetCurrentThreadId.ToString("X8") & Me.Name
Dim th As New Threading.Thread(AddressOf SDummy)
Dim value As Integer
value = th.ManagedThreadId
'end adapted
Dim atomName As String = CStr(value) & "_HotKey"
hotkeyID = GlobalAddAtom(atomName)
If hotkeyID = 0 Then
Throw New Exception("Unable to generate unique hotkey ID. Error code: " &
System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString)
End If
_Key = hotkey
_Modifier = modifiers
' register the hotkey, throw if any error
If RegisterHotKey(frm.Handle, hotkeyID, modifiers, hotkey) = 0 Then
Dim LastError As String = System.Runtime.InteropServices.Marshal.GetLastWin32Error.ToString
Throw New Exception("Unable to register hotkey. Error code: " & LastError)
End If
Return True
Catch ex As Exception
' clean up if hotkey registration failed
UnregisterGlobalHotKey()
Return False
End Try
End Function
' unregister a global hotkey
Sub UnregisterGlobalHotKey()
If hotkeyID <> 0 Then
Try
UnregisterHotKey(f.Handle, hotkeyID)
Catch ex As Exception
End Try
' clean up the atom list
GlobalDeleteAtom(hotkeyID)
hotkeyID = 0
End If
End Sub
Protected Overrides Sub Finalize()
UnregisterGlobalHotKey()
MyBase.Finalize()
End Sub
End Class</pre>
Now I want to use it again but my hotkey isn't working
I define the hotkey in the startup and check it in wndProc routine
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Hotkey = New Classes.HotKey
If Not Hotkey.RegisterGlobalHotKey(Keys.F5, Classes.HotKey.EKeyModifier.Win_Alt, Me) Then
MsgBox("Close key not registered")
End If
End Sub
<pre>
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
' let the base class process the message
MyBase.WndProc(m)
' if this is a WM_HOTKEY message, notify the parent object
Const WM_HOTKEY As Integer = &H312
If m.Msg = WM_HOTKEY Then
' do whatever you wish to do when the hotkey is pressed
Dim key As Keys = ((m.LParam.ToInt64 >> 16) And &HFFFF) 'the charKey
Dim modifier As Classes.HotKey.eKeyModifier = (m.LParam.ToInt64 And &HFFFF) 'Shift Alt Control and/or Windows key
Select Case key.ToString
Case "F5"
EndToolStripMenuItem.PerformClick()
End Select
End If
End Sub</pre>
The WndProc function starts on other messages but not on the hotkey
Where am I wrong?
Thanks
Jan
|
|
|
|
|
Really nobody that can help?
|
|
|
|
|
I'm connecting to an EPP server via TCPclient and it's protected by SSL certificate authentication. The company that provides the EPP server said I needed to get a certificate (not self-signed), upload the CRT file into my user account, and then combine the CRT and KEY files into one (I choose PFX) that I will need to pass with each message in order to invoke an authorization / certificate combination. I've upload the CRT and created the PFX files fine.
I've tested this several ways (SSLstream, NetworkStream, StreamWriter/StreamReader) and none of them have been able to produce me with a readable response. At the same time, neither method produces any exceptions. From my testing it appears that I connect to the server okay, convert my string and write okay, but then either get a blank response or a jibberish response that looks like it might be encrypted? Below are two ways I've tried to do this (SSLstream & NetworkStream). You can see my code, plus a screenshot of the response.
SSLstream
Dim collection = New X509Certificate2Collection()
collection.Import("C:\\Users\\Drew\\Desktop\\testcert\\FIcert.pfx", "password", X509KeyStorageFlags.DefaultKeySet)
Dim store = New X509Store(StoreName.My)
store.Open(OpenFlags.ReadWrite)
Try
For Each certificate As X509Certificate2 In collection
store.Add(certificate)
Next
Finally
store.Close()
End Try
Dim hello As XElement = <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<hello/>
</epp>
Try
Dim client As New TcpClient(DRShost, 700)
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(hello.ToString)
Dim callback As New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallback)
Dim sslStream As New Security.SslStream(client.GetStream(), False, callback)
sslStream.AuthenticateAsClient(DRShost, collection, SslProtocols.[Default], False)
If sslStream.IsAuthenticated Then
MsgBox("IsAuthenticated: " & sslStream.IsAuthenticated)
MsgBox("IsMutuallyAuthenticated: " & sslStream.IsMutuallyAuthenticated)
MsgBox("IsEncrypted: " & sslStream.IsEncrypted)
MsgBox("IsSigned: " & sslStream.IsSigned)
MsgBox("IsServer: " & sslStream.IsServer)
End If
sslStream.Write(data, 0, data.Length)
MsgBox("Sent: " & hello.ToString)
data = New [Byte](256) {}
Dim bytes As Integer = sslStream.Read(data, 0, data.Length)
Dim responseData As String = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
MsgBox("Received: " & responseData)
Catch ex As AuthenticationException
MsgBox(ex.Message)
Catch ex As SocketException
MsgBox(ex.Message)
Catch ex As IOException
MsgBox(ex.Message)
Finally
If sslStream IsNot Nothing Then
sslStream.Close()
End If
End Try
Response:
Screenshot Here
NetworkStream
Dim collection = New X509Certificate2Collection()
collection.Import("C:\\Users\\Drew\\Desktop\\testcert\\FIcert.pfx", "password", X509KeyStorageFlags.DefaultKeySet)
Dim store = New X509Store(StoreName.My)
store.Open(OpenFlags.ReadWrite)
Try
For Each certificate As X509Certificate2 In collection
store.Add(certificate)
Next
Finally
store.Close()
End Try
Dim hello As XElement = <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<hello/>
</epp>
Dim client As TcpClient = New TcpClient(DRShost, 700)
Dim tcpNetStream As NetworkStream = client.GetStream()
Dim sslStream As New Security.SslStream(tcpNetStream, False, New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallback), Nothing)
sslStream.AuthenticateAsClient(DRShost, collection, SslProtocols.[Default], False)
Dim encodedBytes As Byte() = ASCIIEncoding.ASCII.GetBytes(hello.ToString)
tcpNetStream.Write(encodedBytes, 0, encodedBytes.Length)
Dim bytesToReceive As Byte() = New Byte(client.ReceiveBufferSize - 1) {}
Dim bytesRead As Integer = tcpNetStream.Read(bytesToReceive, 0, client.ReceiveBufferSize)
MsgBox("Received : " & Encoding.ASCII.GetString(bytesToReceive, 0, bytesRead))
client.Close()
Response:
Screenshot Here
I thought maybe the response from the second set of code was coming back encrypted, so I changed this line:
Dim bytesRead As Integer = tcpNetStream.Read(bytesToReceive, 0, client.ReceiveBufferSize)
To read from the sslStream instead. However, this just leads to once again receiving a blank response:
Dim bytesRead As Integer = sslStream.Read(bytesToReceive, 0, client.ReceiveBufferSize)
Any help on this would be greatly appreciated. I've scoured the web and tried everything I could think of, but to no avail. I do notice that when I view the string I'm sending it does not contain "". However, I believe that is added automatically by XElement?
|
|
|
|
|