TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nepethya Rana
NA
335
152.8k
String.Format method
Jul 5 2017 9:38 AM
This is my extension method in C#
public static class SqlCommandExt
{
public static SqlParameter[] AddArrayParameters<T>(this SqlCommand cmd, IEnumerable<T> values, string paramNameRoot, int start = 1, string separator = ", ")
{
var parameters = new List<SqlParameter>();
var parameterNames = new List<string>();
var paramNbr = start;
foreach (var value in values)
{
var paramName = string.Format("@{0}{1}", paramNameRoot, paramNbr++);
parameterNames.Add(paramName);
parameters.Add(cmd.Parameters.AddWithValue(paramName, value));
}
cmd.CommandText = cmd.CommandText.Replace("{" + paramNameRoot + "}", string.Join(separator, parameterNames));
return parameters.ToArray();
}
}
I Tried to convert it into VB.net
Module StringExtensions
<Extension()>
Public Function AddArrayParameters(Of T)(ByVal cmd As SqlCommand, ByVal values As IEnumerable(Of T), ByVal paramNameRoot As String, Optional ByVal start As Integer = 1, Optional ByVal separator As String = ", ") As SqlParameter()
Dim parameters = New List(Of SqlParameter)
Dim parameterNames = New List(Of String)
Dim paramNbr As Integer = start
For Each value In values
Dim paramName = String.Format("@{0}{1}", paramNameRoot, paramNbr + +)
parameterNames.Add(paramName)
parameters.Add(cmd.Parameters.AddWithValue(paramName, value))
Next
cmd.CommandText = cmd.CommandText.Replace(("{" + (paramNameRoot + "}")), String.Join(separator, parameterNames))
Return parameters.ToArray
End Function
End Module
But the line Dim paramName = String.Format("@{0}{1}", paramNameRoot, paramNbr + +)
says expression expected. I think "paramNbr + +" is causing the problem.
Please help me
Reply
Answers (
4
)
How Can I generate Alphanumeric Characters Using C#
How to convert Wednesday, July 05, 2017, 20:05 GMT +5:30