Execute a SQL Stored Procedure and process the results [closed]

At the top of your .vb file: Imports System.data.sqlclient Within your code: ‘Setup SQL Command Dim CMD as new sqlCommand(“StoredProcedureName”) CMD.parameters(“@Parameter1”, sqlDBType.Int).value = Param_1_value Dim connection As New SqlConnection(connectionString) CMD.Connection = connection CMD.CommandType = CommandType.StoredProcedure Dim adapter As New SqlDataAdapter(CMD) adapter.SelectCommand.CommandTimeout = 300 ‘Fill the dataset Dim DS as DataSet adapter.Fill(ds) connection.Close() ‘Now, read through … Read more

How to Generate Combinations of Elements of a List in .NET 4.0

Code in C# that produces list of combinations as arrays of k elements: public static class ListExtensions { public static IEnumerable<T[]> Combinations<T>(this IEnumerable<T> elements, int k) { List<T[]> result = new List<T[]>(); if (k == 0) { // single combination: empty set result.Add(new T[0]); } else { int current = 1; foreach (T element in … Read more

Why is True equal to -1

When you cast any non-zero number to a Boolean, it will evaluate to True. For instance: Dim value As Boolean = CBool(-1) ‘ True Dim value1 As Boolean = CBool(1) ‘ True Dim value2 As Boolean = CBool(0) ‘ False However, as you point out, any time you cast a Boolean that is set to … Read more

Get the output of a shell Command in VB.net

You won’t be able to capture the output from Shell. You will need to change this to a process and you will need to capture the the Standard Output (and possibly Error) streams from the process. Here is an example: Dim oProcess As New Process() Dim oStartInfo As New ProcessStartInfo(“ApplicationName.exe”, “arguments”) oStartInfo.UseShellExecute = False oStartInfo.RedirectStandardOutput … Read more

VB.net Need Text Box to Only Accept Numbers

You can do this with the use of Ascii integers. Put this code in the Textbox’s Keypress event. e.KeyChar represents the key that’s pressed. And the the built-in function Asc() converts it into its Ascii integer. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress ’97 – 122 = Ascii codes for … Read more

Serilog – Output/Enrich All Messages with MethodName from which log entry was Called

in case you need a version in C#: public static class LoggerExtensions { public static ILogger Here(this ILogger logger, [CallerMemberName] string memberName = “”, [CallerFilePath] string sourceFilePath = “”, [CallerLineNumber] int sourceLineNumber = 0) { return logger .ForContext(“MemberName”, memberName) .ForContext(“FilePath”, sourceFilePath) .ForContext(“LineNumber”, sourceLineNumber); } } use like this: // at the beginning of the class … Read more