|
You don't. You bind it to a DataSet just like you do now with reading the data from SQL. The only difference is you use the DataSet class' ReadXml method to get the data. This is just one of the .ReadXml()[^] method overloads:
Dim newDataSet As New DataSet
newDataSet.ReadXml(filepath)
To save it back out, it's just as easy:
newDataSet.WriteXml(filepath, XmlWriteMode.WriteSchema)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks again!
Sorry to be a pain, but can you help me with the translation? I'm used to using SQL datasets that have tables:
TickersTableAdapter.Fill(Me.DataSet1.Tickers)
TickersTableAdapter.Update(Me.DataSet1.Tickers)
DataSet1.Tables("Tickers").Select(TDataToGet)
Etc.
Following your instructions, I can read the xml dataset file from disk:
Dim TickersDataSet As New DataSet
TickersDataSet.ReadXml("c:\tickers.xml")
But then how to I get it into a format that I can operate on? Can I make that .xml dataset have tables?
|
|
|
|
|
cstrader232 wrote: Can I make that .xml dataset have tables
Yes. You have to define the .XSD files (XML Schema) which will define the tables and their fields.
The code you posted is VB.NET 2005 code. The two TableAdapter statements just retrieve data from an SQL table and places it in a DataSet object, and writes any changes back to the source table.
Which version of VB.NET are you using?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I'm using vb.net 2005 -- the freeware. Right, what I need to try to do is to treat the .xml file the same way I've been treating the sql file. The idea is to avoid the connection string, and potential problems that could occur with it during deployment. My tables are not at all big.
thank you!
|
|
|
|
|
OK, thanks to your help I managed to get rid of my sql connections and now read and write directly to and from xml files. However, when I do an xmlwrite, the rows keep getting added to the file rather than replaced. I'm tempted to just erase the file and rewrite it each time. But a better solution might be to create a primary key.
Could someone help me with how to tell an xml dataset that a column is the primary key? Do I need to use an xml schema for this?
Thanks!
|
|
|
|
|
I have problem with the code below.
Add(String, System.Drawing.Image, System.EventHandler)
I don't know how to replace System.EventHandeler
Thanks
................
|
|
|
|
|
Are you trying to modify the add button on the toolstrip?
Nathan Lindley
.NET Aficionado
|
|
|
|
|
Here is an example:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.ToolStrip1.Items.Add("test", Nothing, AddressOf ButtonClickedEventHandler)
End Sub
Public Shared Sub ButtonClickedEventHandler(ByVal sender As Object, ByVal e As System.EventArgs)
MessageBox.Show("This is a test.")
End Sub
Mike Lasseter
|
|
|
|
|
What the problem if I want to get text from the name that i added to display in message box
Thanks
-- modified at 22:30 Saturday 7th October, 2006
................
|
|
|
|
|
I would like to know if there is a way to populate the combo box in VB 6 using data from a certain table's field. for example i have a form that holds employee details but i also want to pick department code from another table how do i go about it?
|
|
|
|
|
The easiest way is to make sure that you join both tables in your SQL statement, so you can loop through the records returned and fill it right away.
Otherwise, you have to loop through the parent records, and find the value of the department code (by looping) in the other records.
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
HI
i have an image stored with only solid colors
i want to know color percentage of each color in the image
can u help me how to do it
piyush
|
|
|
|
|
YOu can look at my image processing articles for how to read the pixels of an image directly. VB.NET cannot do this, you'd have to do it in C#. The (slow) alternative is to use the GetPixel method. Then you can either work out the shapes that are the same color, or count colors, depending on how complex the shapes are.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I've got what should be an easy question, but I can't find the correct combination in VB.NET.
I have a drop down list of numbers in a combo box. When I leave the form, I want to know which number was chosen.
NumSamp.SelectedIndex()
tells me which index I've chosen, but I can't get the integer or text value of the entry.
NumSamp.SelectedText() or NumSamp.SelectedValue() both come back as nothing.
There must be an easy way to get the value of the chosen entry, but I can't seem to find it.
Thanks,
Ilan
|
|
|
|
|
why can't you use
Request.form("id of combobox").value
it returns index of number selected by user when he leaves the form
use
document.all("idofcombobox").value in javascript for same value without post back form
|
|
|
|
|
Visual Basic doesn't understand "Request" and since I've never used it, neither do I.
While I'm still in the form, I have the combo box. It is called NumSamp.
It seems to me that I ought to be able to query NumSamp in some easy way to find out which value in a list of values was chosen.
In fact, NumSamp.SelectedIndex() gives me the correct offset in the list of values. I'm just missing the next step: given the index, what is the value of the entry?
Thanks,
Ilan
|
|
|
|
|
NumSamp.SelectedIndex.value
will solve your problem
|
|
|
|
|
Thanks for your kind answer.
|
|
|
|
|
Use NumSamp.SelectedItem . If you're coding with Option Strict On use the .ToString() method as well.
Sample
Private Sub Button1_Click(...) Handles Button1.Click
'pass value of selected item to Form2
Dim frm2 As New Form2
frm2.Text = Me.ComboBox1.SelectedItem.ToString
frm2.Show()
End Sub
|
|
|
|
|
Thanks,
It was under my nose all the time and somehow I missed it.
As I expected, it is really easy.
|
|
|
|
|
Let say i have the data below in a textfile call testing.txt
No,Title
1,Information
2,Error message
3,Question
Now, how can i specify,get and display the second line data?
I would appreciate so much for help!!
|
|
|
|
|
If it's the second line, you can read a line at a time and use the second one. Or you can use a regex to parse the data.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks for help, but can i have sample coding?
|
|
|
|
|
System.IO.File.ReadXXX is the group of methods that are the easiest way to read a file into a string or group of strings.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Sorry for the troublesome! This is some of my code which i only manage to get title as return. May i have some advice on it?
Private Function ReadTextFile(ByVal sFileName As String) As String
Dim s As String = String.Empty
Try
Dim oFile As FileStream = New FileStream(sFileName, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim oReader As StreamReader = New StreamReader(oFile)
s = oReader.ReadLine()
oReader.Close()
oFile.Close()
ReadTextFile = s
Catch
ReadTextFile = "Unable to open file."
End Try
End Function
|
|
|
|