|
Dim dtrReader As SqlDataReader = cmdCommand.ExecuteReader()
Try
While dtrReader.Read()
lstViewBuyers.Items.Add(dtrReader(1))
End While
Finally
dtrReader.Close()
End Try
this is how i display one field from the database to the listview... but my problem is when i come to display one row/record from the database to the listview...
How can i display the whole record in the sql database to using listview control?
pls help
nothing is impossible.....
|
|
|
|
|
By using a string builder to build a string out of the data in the row, and then adding that.
(1) is returning the second column, you can access them by name or index ( name is more self documenting ), you can build the string any way you like. There's no way to make the string build itself.
Christian Graus - C++ MVP
|
|
|
|
|
one way but not a good way is concatinate all of your field together that the query result is become to 1 field e.g.
sql --> "select f1 + ' ' + f2 + ' ' + f3 + ' ' + f4 from TableName"
' ' is white space, f1 to f4 is field name
result --> "aaa aaa aaa aaa"
"bbb bbb bbb bbb"
"cccc ccc cc ccccc"
the output format is not order in column but it's ok if the data is name and surname
|
|
|
|
|
Hi,
I have solved this problem simply as follows:
lstViewBuyers.Items.Add(dtrReader(1) & "|" & dtrReader(2))
I.e. you just concatenate all the fields from the record into a string with a divider between the values.
Afterward, if you want to use any part of the record, selected from the listview, you just itirate through the string. The | character (ofcourse you can use any other character or string) serves as the divider. Something like this:
Dim divider As String = "|"<br />
Dim cut As Integer<br />
Dim TheBitYouNeed As String<br />
cut = TheBitYouNeed.IndexOf(divider)<br />
TheBitYouNeed= Mid(TheBitYouNeed, 1, cut)
Hope this helps you,
Johan
|
|
|
|
|
Hey, another way of doing this if you don't know the amount of columns in the table you are getting would be:
<br />
Try<br />
While dtrReader.Read()<br />
Dim lvItem As New ListViewItem(dtrReader(0))<br />
For i As Integer = 1 To dtrReader.FieldCount - 1<br />
lvItem.SubItems.Add(dtrReader(i))<br />
Next<br />
lstViewBuyers.Items.Add(lvItem)<br />
End While<br />
<br />
Finally<br />
dtrReader.Close()<br />
End Try<br />
Bsically the same thing, but since the data reader has field information on it, we just use that and create the sub items from the datareader starting at the 1 position. Have you thought of using a bindable list view?
You may want to check to see if nulls are coming back though, you may get exceptions when you get data from a datareader that has null values and try to add it to a list view item like this.
|
|
|
|
|
Excel can load a CSV. A CSV is just a file, it can't do ANYTHING, except represent data. If you open a .CSV file in Excel, it will open with each comma being a column.
Christian Graus - C++ MVP
|
|
|
|
|
|
I have no idea. You asked about a CSV. If you can get MySQL data into a CSV, Excel will jsut open it.
Christian Graus - C++ MVP
|
|
|
|
|
There are MySQL tools available that can export to CSV files. You might want to look at SQLYog, for one.
|
|
|
|
|
How do class work?
a simple question for you maybe but its hard for me to understand... pls i need ur help
nothing is impossible.....
|
|
|
|
|
I have no idea what you're asking. How do you mean ?
A class represents a unit of operation. Once you have a class, you can create an instance of that class ( or as many as you like ), and use it's methods to perform the operations that class defines, access it's properties to get access to the data that class contains, etc.
If that doesn't help, then you need to ask a more specific question. From what angle are you asking ? Have you done any coding yet ?
Christian Graus - C++ MVP
|
|
|
|
|
i already made one class but on how to use it from the other form i dont know.... my simple class is just to get the sum of two integers.
will you help a simple mind like me to understand how to use class?
nothing is impossible.....
|
|
|
|
|
I guess the important question is - what resources do you have that you will be able to proceed once I tell you ? Sounds like you need to buy a book and work through it.
If your class is called wotsit, then you do this:
Dim w as wotsit = new wotsit() ( because VB syntax is nasty. You can call it whatever you like )
w.CallAnyMethodHere
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
i really appreciate your quick response... even though it sound really 'dumb' question, but you really do me a very big favor... thanks, i used your syntax and it really work..
nothing is impossible.....
|
|
|
|
|
I have an application that runs a secondary, child, thread. That secondary thread can write to a public data table bound to the main form. However, it cannot write to a public textbox on the main form. Why is that?
tia
|
|
|
|
|
Because .NET 2.0 blocks UI access between threads. You can turn this off, or use a WorkerThread ( from memory ), which sends messages to the main thread, where you can update your UI.
Christian Graus - C++ MVP
|
|
|
|
|
Windows Forms are not thread safe, since you want to update the textbox from another thread you will need to marshal the update method to the original thread (the main form thread) and execute the method there.
Code might look like this:
Delegate Sub TextDelegate(ByVal Text As String) 'Declared Somewhere
Sub SetText(ByVal Text As String) 'Declared Somewhere
Me.TextBox1.Text = Text
End Sub
'From second thread
If TextBox1.InvokeRequired Then TextBox1.Invoke(New TextDelegate(AddressOf SetText), "Hello")
'If calling from a second thread, create a bridge (Delegate) to a custom sub on the fly and tell the first thread to execute it through the safe bridge
Hope this clarifies something
|
|
|
|
|
Thanks, that's helpful... but....
Textbox1.invokeRequired returns false and yet
textbox1.text = "Hello"
still doesn't write to the textbox.
How can that be?
|
|
|
|
|
Would you mind posting a small code snippet, please?
|
|
|
|
|
HI Yone!
Thanks for your help. I'm still puzzled. Here is the thing..
The test buttonpress routine below calls the backgroundworker which then prints to the textbox using the delegate. This works fine.
However, the same call from the application sub does not invoke the delegate!
'THIS IS THE SUB THAT CALLS THE WRITETOLOG FUNCTION FROM ANOTHER CLASS
Public Class Application
Public Sub onLogon()
Implements QuickFix.Application.onLogon
Form1.WriteToLog("Logon Successful")
End Sub
End class
'THIS IS THE CLASS THAT HAS THE TEXTBOX
Public Class Form1
Public Function WriteToLog(ByVal Whattowrite)
'THIS WORKS FINE IF CALLED FROM BUTTONPRESS BELOW
'THIS IS IGNORED IF CALLED FROM APPLICATION CLASS SUB ABOVE
If TextBox1.InvokeRequired Then
TextBox1.Invoke(New TextDelegate(AddressOf SetText), _
TextBox1.Text & Whattowrite & vbCrLf)
End If
If Not TextBox1.InvokeRequired Then
TextBox1.Text = TextBox1.Text & "Not" & Whattowrite &
vbCrLf
End If
End Function
Sub SetText(ByVal Text As String) 'Declared Somewhere
TextBox1.Text = Text
End Sub
Delegate Sub TextDelegate(ByVal Text As String) 'Declared Somewhere
'BELOW IS ROUTINE TO TEST THE WRITETOLOG FUNCTION FROM A
BACKGROUND THREAD (WORKS FINE)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e _
As System.EventArgs) Handles Button1.Click
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As _
System.Object, ByVal e As _
System.ComponentModel.DoWorkEventArgs) _
Handles BackgroundWorker1.DoWork
WriteToLog("From BWorker")
End Sub
|
|
|
|
|
When your calling the sub onLogon() it calls the WriteToLog() method on another Form1 Class, (its just a class as any other class) You need to somehow pass a reference to the original Form1 class that was created when your application started to the Application Class, and call WriteToLog() on that reference.
Code might look like this:
'Class Declaration
<br />
Public Class Application<br />
Public frm As Form1 = Nothing<br />
<br />
Public Sub onLogon()<br />
If frm IsNot Nothing Then frm.WriteToLog("Hello from Application class")<br />
End Sub<br />
End Class<br />
'From any sub or other thread:
<br />
Dim a as New Application<br />
a.frm = me<br />
a.onLogon<br />
I tested it and it worked in my test setup
|
|
|
|
|
I'm using Crystal Reports in my vb.net project, for some reason this version of Crystal Reports is designed to disable mouse scroll or keyboard scroll. Is there any way I can enable the scroll by writing some code, because the only other way to enable the scroll is to do an upgrade.
Thanks,
Zee
|
|
|
|
|
Dim ParamSeparator() As String = {"GIF89a"}<br />
Dim gif As String = File.ReadAllText(OpenFileDialog1.FileName)<br />
For Each files As String In gif.Split(ParamSeparator, StringSplitOptions.None)<br />
<br />
Next
I wrote this code but it didn't work with Binary Files, so i want to know how to edit it for make working with Binary FIles.
Thanx for any help
|
|
|
|
|
Why did you do this when I told you what to do the last time you asked this question ?
Christian Graus - C++ MVP
|
|
|
|
|
Hello
I am makeing a quiz application and I am haveing problem with randomize
In multiple section I put 4 options and 3 is wrong answers and 1 is right answer so i randomize the questions but i also want to randomize the answers in lebels boxes so any help how to ransomize the answers
i used arrays for example how i create quiz
qus(0)="This the question ?" : ans1(0)="A" : ans2(0)="B" : ans3(0)="C" : ans4(0)="D"
thet's how i create array to display questions and it's options
and i put 4 buttons and 4 labels in front of it
and answers display in labels
lblA.txt = ans1(I)
lblB.txt = ans2(I)
lblC.txt = ans3(I)
lblD.txt = ans4(I)
any help please
|
|
|
|