.net-1.1

How to split a string into a fixed length string array?

谁说胖子不能爱 提交于 2019-11-29 15:01:51
I have a long string like this dim LongString as String = "123abc456def789ghi" And I want to split it into a string array. Each element of the array should be in 3 characters length For example, Dim LongArray(5) As String LongArray(0) = "123" LongArray(1) = "abc" LongArray(2) = "456" LongArray(3) = "def" LongArray(4) = "789" LongArray(5) = "ghi" How do I split it using VB.net code? This could work. Module Module1 Sub Main() Dim LongString As String = "123abc456def789ghi" Dim longlist As New List(Of String) For i As Integer = 0 To Convert.ToInt32(LongString.Length / 3) - 1 longlist.Add

How can I assign the value selected in a listbox to an enum var?

China☆狼群 提交于 2019-11-28 14:50:46
I want to avoid the kludginess of: private void listBoxBeltPrinters_SelectedIndexChanged(object sender, System.EventArgs e) { string sel = string listBoxBeltPrinters.SelectedItem.ToString(); if (sel == "Zebra QL220") { PrintUtils.printerChoice = PrintUtils.BeltPrinterType.ZebraQL220; } else if (sel == "ONiel") { PrintUtils.printerChoice = PrintUtils.BeltPrinterType.ONiel; } else if ( . . .) } Is there a way I can more elegantly or eloquently assign to an enum based on a list box selection, something like: PrintUtils.printerChoice = listBoxBeltPrinters.SelectedItem.ToEnum(PrintUtils

Looking for best practice for doing a “Net Use” in C#

对着背影说爱祢 提交于 2019-11-27 07:41:28
问题 I'd rather not have to resort to calling the command line. I'm looking for code that can map/disconnect a drive, while also having exception handling. Any ideas? 回答1: Use P/Invoke and WNetAddConnection2 There should also be some wrappers out there to do some of the grunt work for you. Google is your friend, as always. 回答2: Here is an article for using a class for interfacing to the "map network drive" windows interface: C# Map Network Drive (API) 来源: https://stackoverflow.com/questions/8919

Does DataAdapter.Fill() close its connection when an Exception is thrown?

坚强是说给别人听的谎言 提交于 2019-11-27 01:56:28
问题 I am using ADO.NET (.NET 1.1) in a legacy app. I know that DataAdapter.Fill() opens and closes connections if the connection hasn't been opened manually before it's given to the DataAdapter. My question: Does it also close the connection if the .Fill() causes an Exception? (due to SQL Server cannot be reached, or whatever). Does it leak a connection or does it have a built-in Finally-clause to make sure the connection is being closed. Code Example: Dim cmd As New SqlCommand Dim da As New

SqlDataAdapter.Fill method slow

扶醉桌前 提交于 2019-11-27 00:31:08
Why would a stored procedure that returns a table with 9 columns, 89 rows using this code take 60 seconds to execute (.NET 1.1) when it takes < 1 second to run in SQL Server Management Studio? It's being run on the local machine so little/no network latency, fast dev machine Dim command As SqlCommand = New SqlCommand(procName, CreateConnection()) command.CommandType = CommandType.StoredProcedure command.CommandTimeout = _commandTimeOut Try Dim adapter As new SqlDataAdapter(command) Dim i as Integer For i=0 to parameters.Length-1 command.Parameters.Add(parameters(i)) Next adapter.Fill

SqlDataAdapter.Fill method slow

北城以北 提交于 2019-11-26 08:07:34
问题 Why would a stored procedure that returns a table with 9 columns, 89 rows using this code take 60 seconds to execute (.NET 1.1) when it takes < 1 second to run in SQL Server Management Studio? It\'s being run on the local machine so little/no network latency, fast dev machine Dim command As SqlCommand = New SqlCommand(procName, CreateConnection()) command.CommandType = CommandType.StoredProcedure command.CommandTimeout = _commandTimeOut Try Dim adapter As new SqlDataAdapter(command) Dim i as