|
Unfortunately, I have no control on the database.
|
|
|
|
|
OK. let's see what your code looks like that is storing the XML and retrieving it.
|
|
|
|
|
Actually I don't have my code on hand, but the code look like this:
Dim ms As IO.MemoryStream = New MemoryStream()
Dim w As XmlTextWriter = New XmlTextWriter(ms, Encoding.UTF8)
w.WriteStartDocument()
' create the xml doc by adding element, attribut etc...
w.WriteEndDocument()
w.Flush()
ms.Position = 0
Dim sr As StreamReader = New StreamReader(ms)
Dim strXML As String = sr.ReadToEnd()
Now I have a string that have my xml doc, but because the string type is UTF-16, I need to convert in UTF-8. I can create an array of bytes with the correct encoding like this:
Dim enc As New System.Text.UTF8Encoding()
Dim dBytes As Byte() = enc.GetBytes(strOutput)
I now have an array of byte with the proper encoding but how can I save that in the database where the field is of type ntext?
|
|
|
|
|
What's with the MemoryStream? Why are you not just using a normal SqlParameter object to store the XML text in the field?
|
|
|
|
|
Not sure to understand your question. The memoryStream is used as a container to hold the data created by the XmlTextWriter. Are you suggestion to used the memoryStream has the parameters of a SqlParameter like this:
Dim ms As IO.MemoryStream = New MemoryStream()
Dim w As XmlTextWriter = New XmlTextWriter(ms, Encoding.UTF8)
w.WriteStartDocument()
' create the xml doc by adding element, attribut etc...
w.WriteEndDocument()
w.Flush()
ms.Position = 0
sqlCmd.Parameters.Add(New SqlParameter("@xmlData", SqlDbType.nText))
sqlCmd.Parameters("@xmlData").Value = new SqlXml(ms)
sqlCmd.ExecuteNonQuery
|
|
|
|
|
Convert the MemoryStream to a normal, everyday String and pass the string as a parameter to query.
|
|
|
|
|
Dave, correct me if I'm wrong but if I pass the everyday string type as a parameter, I will have stored an UTF-16 encoding instead of the UTF-8 that I need. The other application that will read the content of that field, will expect an UTF-8 encoding and parse the information to recreate the XML file. (And of course, I have no control on the other application!)
|
|
|
|
|
It gets stored as whatever the original string was. It will NOT change the encoding at all.
Besides, all Strings are Unicode in .NET.
Did you also know that the NTEXT type is deprecated and will be removed from future SQL Servers?
|
|
|
|
|
Thanks Dave for your valuable input.
|
|
|
|
|
TremaHD wrote: The XML parser expect an UTF-8 encoding
why is that?
Can't you just forget about UTF8/UTF16, and store and retrieve strings using Unicode?
i.e. remove the explicit encoding where you open your StreamWriter/StreamReader.
|
|
|
|
|
Hello all
I am building a remote control application on my PDA running WM2003.
I do this using tcplistener and sockets.
I have run into a small problem where I dont know how to do it.
On my main app I have a messagebox opening with ok, cancel.
I want to press OK or Cancel using the remote app on the PDA, any idea how to do this?
Greetings
SiX
|
|
|
|
|
SiXke wrote: I am building a remote control application on my PDA running WM2003.
Remote controling what? Your application, or the entire Desktop on the system?
SiXke wrote: On my main app I have a messagebox opening with ok, cancel.
I want to press OK or Cancel using the remote app on the PDA, any idea how to do this?
This is your app. If your remote controlling just your app, the entire interface is up to you. Provide some method to notify the client that the MessageBox is there and some way for the client to tell the app to dismiss the message box.
If your controlling the entire Desktop and not just your app, Google for "VNC Client". See if anyone has a library that will work with your Windows PDA.
|
|
|
|
|
Hi.
I hope I am in the correct forum for this.
If I create an Excel 2007 Application, will it work in Excel 2003 on the End Users computer?
I have Visual Studio 2008 and Excel 2007 Professional but most of my Clients (About 360) still have Excel 2003
|
|
|
|
|
|
I'm 99% sure that the default file format for an Excel 2007 spreadsheet is incompatible with Excel 2003. I also believe that there is a special reader/converter that can be installed on Excel 2003 to read the Excel 2007 formats.
Check this out from Microsoft
http://office.microsoft.com/en-us/excel/HA100141071033.aspx[^]
|
|
|
|
|
No, it's not going to work. You have to develope your code against the lowest version of Office you're going to support. If you wrote it against 2003, it'll still work with 2007.
|
|
|
|
|
Hi,
I have a popup menu items which will be invoked when we right click on a particular file.
My popupmenu
...AddTestCase...OpenFile
...DeleteFile
Now on right click all the three submenus are getting displayed.
But I want AddTestCase menu to be visible only when i rightclick on a HTML file.
Please Help.
Thanks,
Karthick.M
|
|
|
|
|
I take it that you are using a ContextMenuStrip to build the Popup Menu. I am also unsure where you are right clicking, whether it is a list box, listview, textbox or what, but the ContextMenuStrip has an Opening event which fires when opening (really ). You can use this event to check whether the filename ends with ".html" and then use the ContextMenu Items Visible property to display or hide the Item. I did a test with a label like so :
Private Sub ContextMenuStrip1_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)Handles ContextMenuStrip1.Opening
If Label1.Text Like "*.html" Then
ContextMenuStrip1.Items(2).Visible = True
Else
ContextMenuStrip1.Items(2).Visible = False
End If
End Sub
and it works fine.
|
|
|
|
|
Thank you It Worked.
|
|
|
|
|
|
I've been using VB.Net since its release, and I only now learn that there is a Like operator. The things I learn here.
Added: Looking for more info, I find that Like has been around since at least VB6. Crimeny, this would have been useful to know!
|
|
|
|
|
Hello,
I need your help.
I would like to handle two Excel books with VB.net.
Here is a part of my code:
Dim ExcelApp As Object
Dim ExcelBook As Object
Dim ExcelSheet As Object
ExcelApp = New Excel.Application
ExcelApp.Visible = True
ExcelBook = ExcelApp.Workbooks.Open(Folder & "List2")
ExcelBook = ExcelApp.Workbooks.Open(Folder & "List1")
ExcelApp.Workbooks("List1.xlsx").Activate
'Add data to cells of the first workbook
ExcelSheet = ExcelBook.Worksheets(1)
ExcelSheet.Range("A1").Value = "Book 1"
ExcelSheet.Range("B1").Value = "First Name"
ExcelSheet.Range("A1:B1").Font.Bold = True
ExcelSheet.Range("A2").Value = "Max"
ExcelSheet.Range("B2").Value = "Paul"
ExcelApp.Workbooks("List2.xlsx").Activate ' doe not work
'Add data to cells of the second workbook
ExcelSheet = ExcelBook.Worksheets(1)
ExcelSheet.Range("A1").Value = "Book 2"
ExcelSheet.Range("B1").Value = "First Name"
ExcelSheet.Range("A1:B1").Font.Bold = True
ExcelSheet.Range("A2").Value = "Egon"
ExcelSheet.Range("B2").Value = "Franz"
How can I set "List2.xlsx" active to read and write in List2.xlsx and switch back to "List1.xlsx"
The code to activate List2 does not work.
Thanks in advance
Stephan
|
|
|
|
|
I don't do Office Interop, so this may seem like a stupid question.
Why do you even need to call .Activate? All you're doing is setting cell values. You don't have to have the sheet as the "active" sheet to do that. Activate does not turn a sheet from "ReadOnly" to "ReadWrite". All it does is make it the currently viewed sheet, just like you clicked its tab at the bottom of the Excel window.
If you're trying to show a specific sheet to the user, then try following up the call to Workbook.Activate with a Worksheet.Activate that's in that workbook.
|
|
|
|
|
What I will do is to open two or more Excel files with VB.net.
After that I will start to search an value in the first Excel sheet.
If I don't find the value I start the seach again in the next sheet.
The question for me is, how can I chance to different workbooks in the Excel application with VB.net via Office Interop.
Do you have a pice sample code how I can do that.
|
|
|
|
|
stephan0607 wrote: how can I chance to different workbooks in the Excel
If you're asking how you can CHANGE to a different workbook, you already did it in your code. There's a Workbooks collection in the Excel object. In each Workbook object, there is a Worksheets collection.
stephan0607 wrote: Do you have a pice sample code how I can do that
I already said I don't do Office Interop. I'm going entirely on the documentation for the Excel object model.
|
|
|
|