|
I am having trouble getting VB to interact with a MySQL server, which was setup for the purpose of keeping track of points for members of a group. The application is to display a DataGridView of an already created table which is on the MySQL server. The members would edit the table on the DataGridView, and Add or Remove a member based on a button command.
What I have read is that, by using XML, it is possible to simply connect to the database, collect the table required to display, and then disconnect (also for updating the altered data). However, since I am unable to connect to the database, the single-form layout which I had designed doesn't work. I am unable to get this to work, and have tried for weeks.
I am very lost and slightly frustrated at this. I have read every online tutorial which I can find, even other forums, etc. And still...nothing Any help will be greatly appreciated.
|
|
|
|
|
Would I be better off using MSSQL and running it from my machine?
|
|
|
|
|
|
I was actually writing it for SQL and not MySQL ><. Thanks a lot. BTW, Do you have any other links like that which give helpful source code?
|
|
|
|
|
how to get process name from a process ID.. that will return a complete process name(e.g YAHOOMESENGER.exe) not that like msdos filename(e.g YAHOOM~1.exe)
-- modified at 1:08 Tuesday 9th January, 2007
|
|
|
|
|
have you tried:
Dim o As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessById(2844)
MsgBox(o.MainWindowTitle & "(" & o.ProcessName & ")")
|
|
|
|
|
Hello everybody, I wrote the following code snippet to establish a TCP Listener – Client connection. I use a state machine to loop this sub in a thread so that it can continuously receive data from the client.
But there are few problems that I don not know how to handle.
First, if a client is already connected to the TCP listener and the client closed this connection at the remote side, how can I detect this connection loss? For example, I use the HyperTerminal to create a WinSock connection to TCP listener and disconnect it in the HyperTerminal.
Second, how do I handle multiple connections simultaneously?
I do appreciate your help.
<br />
Public Sub socketHandler()<br />
Dim _HostSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP)<br />
Dim _TcpListener As New TcpListener(IPAddress.Parse(getLocalIP), Integer.Parse(TextPortListen.Text))<br />
<br />
Try<br />
<br />
While True<br />
<br />
Select Case sockStatus<br />
<br />
Case socketStatus.SOCKET_IDLE<br />
'does not do anything but wait<br />
<br />
Case socketStatus.SOCKET_STOP<br />
_TcpListener.Start()<br />
sockStatus = socketStatus.SOCKET_LISTEN<br />
<br />
Case socketStatus.SOCKET_LISTEN<br />
<br />
If _TcpListener.Pending = True Then<br />
_HostSocket = _TcpListener.AcceptSocket<br />
sockStatus = socketStatus.SOCKET_CONNECTED<br />
End If<br />
<br />
Case socketStatus.SOCKET_CONNECTED<br />
<br />
If _HostSocket.Poll(1, SelectMode.SelectRead) Then<br />
' _HostSocket has data to be read. <br />
' Call the Socket Available method on _HostSocket; <br />
' assign the return value (Bytes available) to an integer variable. <br />
Dim numBytes As Int32 = _HostSocket.Available<br />
' Instantiate an array of Bytes which is the size of the <br />
' number of Bytes available. <br />
Dim Data(numBytes) As Byte<br />
' Call the Socket Receive method. <br />
' Receives data from a connected Socket. <br />
_HostSocket.Receive(Data)<br />
' Convert the Byte array received into a String <br />
SetText(Encoding.ASCII.GetString(Data), TextRxData)<br />
End If<br />
<br />
Case socketStatus.SOCKET_CLOSING<br />
<br />
If _HostSocket.Connected Then<br />
_HostSocket.Close()<br />
End If<br />
_TcpListener.Stop()<br />
sockStatus = socketStatus.SOCKET_CLOSED<br />
<br />
<br />
Case socketStatus.SOCKET_CLOSED<br />
'the current socket connection is closed. set to idle status<br />
sockStatus = socketStatus.SOCKET_IDLE<br />
End Select<br />
<br />
End While<br />
<br />
Catch ex As Exception<br />
MsgBox(ex.Message.ToString)<br />
End Try<br />
<br />
End Sub<br />
-- modified at 22:11 Monday 8th January, 2007
|
|
|
|
|
I'm just learning VB, (a nug) I'm told that msdn can be very helpful.
is msdn a "redistributable"? I'm trying to find it, not having much luck as I'm not finding anything that is called Just "Msdn" Help? J.Paul Ghetty
|
|
|
|
|
You won't find any VB6 help in MSDN. VB6 has been obsolete for about 5 years and unsupported by MS for a fair while now. Why are you learning it ? If you want to learn to program for anything other than a laid back hobby, VB6 is a bad idea.
MSDN comes on CD with visual studio, unless you download a free version ( VB Express Edition is what I'd be recommending to you ). It's also a website - msdn.microsoft.com[^].
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Any help would be appreciated.
I am trying to design my form to display the data using a Selected Value from a listbox. I set the lbShop.SelectedIndexChanged event to refresh the datagrid when a new value is selected. The variable SShop1 is changed correctly as each item in the listbox is selected, but the datagrid will not refresh using the SQL Select string. What I need is the new SQL Select command to run with the user selected variable, clear the datagrid, and display the data from the new SQL string.
Private Sub frmAllOpenbyShop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cnn.Open()
reader = dr5.ExecuteReader()
While reader.Read()
values.Add(reader.Item("Shops").ToString())
End While
lbShop.DataSource = values
reader.Close()
Try
'Attempt to load the dataset.
Me.loadDoc()
Catch eLoad As System.Exception
'Add your error handling code here.
'Display error message, if any.
System.Windows.Forms.MessageBox.Show(eLoad.Message)
End Try
End Sub
*******************************************************************************
Public Sub dadapt1()
SShop1 = lbShop.SelectedItem
DAdapt.SelectCommand = New SqlCommand
DAdapt.SelectCommand.CommandType = CommandType.Text
DAdapt.SelectCommand.Connection = cnn1
DAdapt.SelectCommand.CommandText = "Select SystemName, Shop, ActionTaken, TaskNotes, Symptoms, TroubleShooting, Conclusion FROM Workorders WHERE TaskNotes LIKE '" & SShop1 & "' ORDER BY Shop"
End Sub
*******************************************************************************
Public Sub loadDoc()
Me.dadapt1()
Try
dsSearch2.Clear()
DAdapt.Fill(dsSearch2)
Catch ex As SqlException
End Try
grdWorkorders.DataSource = dsSearch2
End Sub
*******************************************************************************
Private Sub lbShop_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbShop.SelectedIndexChanged
grdWorkorders.Refresh()
Me.loadDoc()
End Sub
LWhite
|
|
|
|
|
If you want to do a LIKE query, you need to put the wildcards in, otherwise just use =.
This is not production quality code, a SQL injection attack will perform whatever SQL the malicious user wants to run on it.
Haev you stepped through to see how the code is being executed ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thank you, I replaced the LIKE with = as I didn't need a wildcard search anyway. I will have to look at tightening the code to protect from attack. I stepped through the code and find that if I leave the SShop1 variable = nothing, I get my entire database, as expected, but when I try to set the variable to = a selection from the listbox, I get nothing displayed, just an empty datagrid. This is the line I rem'd out to get a default variable of nothing: SShop1 = lbShop.SelectedItem
Thank you for responding to my question.
Larry
LWhite
|
|
|
|
|
I want to be able to move the minimized form. not change the location for when it restores. I want to minimize it with a left property of 190.
Jason Holland
Stockroom Manager
AE&C Services
|
|
|
|
|
You don't have access to that. The MdiClient control controls the position of minimized (iconed) windows.
Why do you want to do this anyway?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello everyone.
I've read several articles on the internet in trying to figure this out; however, those article seem a bit over my head apparently and I can't seem to find a code example that is simple and to the point to implement.
I'm coding a password manager program in vb 2005. All that is left to do is obtain a password from the user the first time they start the program, and use that password as the encryption key in creating the file that will hold the data from the listview control.
For now, the login form is simply taking the password the user enters and encrypting it inside a separate file for now as you will see below - the file itself is not encrypted. I have all the forms complete and the listview data is writing to a currently unencrypted file for now. I just want to make it all one file with the user password being the key to encrypt it all.
Here is the login code I'm using if we can somehow modify it to do what I'm looking for:
If txtUserPsw.Text = txtPswVerify.Text And Me.txtPswVerify.Text.Length >= 8 Then
Try
' Obtain a FileStream object.
Dim aFileStream As New FileStream(AppPath(False) & "\passsafe.bin", FileMode.Create)
' Obtain a BinaryWriter object.
Dim aBinaryWriter As New BinaryWriter(aFileStream)
' Encrypt the new password and binary write to a binary file.
aBinaryWriter.Write(EncryptPassword.EncryptString(Me.txtPswVerify.Text))
' Close the FileStream and the BinaryWriter objects.
aFileStream.Close()
aBinaryWriter.Close()
' Message user.
MessageBox.Show("Password was encrypted and saved. Don't forget it!")
'Display Main form (Frmlogin)
Dim safe As New frmSafe
'Hides login form
Me.Visible = False
safe.ShowDialog()
'disposes login form on exit of main form
'Application.Exit()
Me.Close()
Catch ex As Exception
' Message user.
MessageBox.Show("Password was not saved. ERROR: " & ex.Message)
End Try
End If
Thanks everyone!
Sincerely,
Harold
|
|
|
|
|
Im trying to print a document in landscape. But it seems my program only print in regular orientation, that is the on ive set in the printer driver under Start->Settings->Printer and faxes.
Im using the QueryPageSettings sub when it prints and set e.PageSettings.Landscape = True but nothing happens.
Anyone got same problems or have any ideas?
Thanks
|
|
|
|
|
|
Your code has some problems. Like if you're going to use this code again and again, I don't see anything to clear out the existing columns so you don't end up adding a new set of columns to the ones that are already there.
Next, what is Col in this line and why are you adding it 3 times?
DataGridView.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Col1, Col, Col, Col})
This code isn't making much sense. The Me's tell me that you have DataGridViewColumn objects sitting on the form???
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks Dave for your reply ..
Really I'm waiting you and you for reply ,, and I still rememper you every day and rememper your words ,, God bless you !
I'm sorry that I mean on this line
DataGridView.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Col1, Col2, Col3, Col4})
I want to understand what i mean , see , I'm using Master/Details form,
and I did an ides which when the user add or edit then I copy the details records to a temp table , then after that when save the program copy all recors from temp taple to Base table , is idea is good on many sides ,, I see that,
from that I change the DataSource and DataMember of DataGridView , then I found that the order and header text of columns is changed , then I try to solve that problem by that , on every action the program clear all columns an reAdd it with it's propertis that I need , then the Problem that I entioned it on first message faced me ,, I hope you see ,,
jooooo
|
|
|
|
|
I suggest straightening out your column code and create then add each column as you make it. Oh! For future posts, copy and paste the actual code you're using. DO NOT RETYPE IT in the post yourself. You're more likely to cover up the problem with other mistakes if you do.
Private Sub AddCol()
Dim newCol As New DataGridViewTextBoxColumn ' NOT DataGridViewColumn!
newCol.DataPropertyName = "Field1"
newCol.HeaderText = "Col1"
newCol.Width = 40
DataGridView1.Columns.Add(newCol)
newCol = New DataGridViewTextBoxColumn
newCol.HeaderText = "Col2"
newCol.Width = 40
DataGridView1.Columns.Add(newCol)
....
End Sub
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
I'm having a problem printing (i'm really sending it a string in its own language) to a shared network printer.
I have written the following code:
Dim idFile As Integer = FileSystem.FreeFile
FileSystem.FileOpen(idFile, "\.0.0.1\ZebraLP2844", OpenMode.Append, OpenAccess.Write, OpenShare.Shared)
strTemp = "N" & vbCrLf 'Clear Buffer
strTemp = strTemp & "q816" & vbCrLf 'Label Width in dots (4 inches?)
strTemp = strTemp & "Q203,24+0" & vbCrLf 'Label Height and gap in dots (1 inch)
strTemp = strTemp & "S2" & vbCrLf 'S = Speed Select
strTemp = strTemp & "D10" & vbCrLf 'D = Density
strTemp = strTemp & "ZT" & vbCrLf 'Direction set to forward? (ZT is what u want)
strTemp = strTemp & "OD" & vbCrLf 'Direct Thermal Mode
strTemp = strTemp & "A25, 12, 0, 5, 4, 2, N, """ & myName & """" & vbCrLf
strTemp = strTemp & "LO50, 5, 800, 20" & vbCrLf
strTemp = strTemp & "A75, 12, 0, 5, 4, 2, N, """ & mySN & """" & vbCrLf
strTemp = strTemp & "P" & numCDPrint.Value().ToString & vbCrLf
FileSystem.Print(idFile, strTemp)
FileSystem.Reset()
But on line:
FileSystem.FileOpen(idFile, "\.0.0.1\ZebraLP2844", OpenMode.Append, OpenAccess.Write, OpenShare.Shared)
I Recieve this error message:
"FIleStream was asked to open a device that was not a file. For support for devices like 'com1:' or 'lpt1:', call CreateFile, then use the FileStream constructors that take an OS handle as an IntPtr."
I'm converting an Old VB6 project to VS.NET. This code in VB6 works with no problem:
Open "\.0.0.1\ZebraLP2844" For Output As #1
strTemp = "N" & vbCrLf ''' Clear buffer
strTemp = strTemp & "q811" & vbCrLf ''' Label Width in dots (2 inches)
strTemp = strTemp & "Q1217,1" & vbCrLf ''' Label height and gap in dots (1 inch)
strTemp = strTemp & "S" & Trim(Me.strSpeed) & vbCrLf
strTemp = strTemp & "D" & Trim(Me.strDensity) & vbCrLf
strTemp = strTemp & "ZT" & vbCrLf ''' Direction
strTemp = strTemp & "OD" & vbCrLf ''' Direct Thermal mode
strTemp = strTemp & "A25,12,0,4,1,1,N,""" & sFirstLine & """" & vbCrLf
strTemp = strTemp & "A25,45,0,4,1,1,N,""" & sSecondLine & """" & vbCrLf
strTemp = strTemp & "A25,78,0,4,1,1,N,""" & sThirthLine & """" & vbCrLf
strTemp = strTemp & "P" & Trim(intQty)
''' End of the EPL2 code
Print #1, strTemp
Close
Any help on how to send this stream/string/file to my shared printer using VS.NET would be greatly appreciated!!
|
|
|
|
|
You can't use the File Stream objects to do this. They can only be used on actual files.
You're looking for something more like this[^] example.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I need a way to tell if 2 images are the same. more specifically, i need to know if 2 screen shots taken less than one second apart are the same or are different. I have tryed using the Image1.Equals(Image2) but this apparently just compares objects and not the data contained with in them. I found some obscure code on sourceforge, but im not sure i will be able to convert it to do what i want it to do. Also I am assuming that if i take 2 screen shots and nothing on the screen has changed, that the 2 resulting images should be identical pixel for pixel. I could be wrong on this part, but i have no way to test this as of yet. suggestions please.
|
|
|
|
|
My image processing articles show how to access the bits of a bitmap. Then it's a snap to iterate over them and see if any have changed.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|