srider1969

I am failing to see how I have NOT clearly demonstrated I know what an Action delegate is. Or how ANY of my POSTED code requires the need for a Func delegate.

srider1969

The third one works.

srider1969

A quick check against the Java engine in RegexBuddy shows my first re named grouping is different somehow.

Favorite language/favorite tool!

srider1969

Or

(?<=\()((?:,?)[\w\s\.]+){3}(?=\))

to target all items between the parentheses.

srider1969

Your first question leads to named groups. To capture something specific it is easier to give it a name.

\w+\((?<first>[\w\s\.])+,(?<second>[\w\s\.])+,(?<third>[\w\s\.])+\)

Your second question could be reduced to

,?[\w\s\.]+

.

What language are you using to run your regex?

srider1969

For the constructor at the class scope. My fourth post help me discover that the properties worked fine as well as the class level Action to void constructor and the program scope constructors.

I am just curious if that is by design or something else.

srider1969

That is at the heart of the question. The collection initializer (for Generics or just the Dictionary?) only accepts void at runtime when Action is specified.

srider1969

Why would a Dictionary of string to Action's collection initializer require a void method at class scope?

Testing the above showed that dsa3 will throw a NullReferenceException on the Action delegate and not the void.

srider1969

I've been looking at the problem and stumbled my way to:

private static Dictionary<string, Action> dsa1 { get { return new Dictionary<string, Action>() { { "one", dsa1TestOne } }; } }
private static Dictionary<string, Action> dsa2 { get { return new Dictionary<string, Action>() { { "one", dsa2TestOne } }; } }

private static Dictionary<string, Action> dsa3 = new Dictionary<string, Action>()  { { "one", dsa1TestOne } };
private static Dictionary<string, Action> dsa4 = new Dictionary<string, Action>() { { "one", dsa2TestOne } };        

static void Main(string[] args)
{
    Dictionary<string, Action> dsa3_again = new Dictionary<string, Action>()  { { "one", dsa1TestOne } };
    Dictionary<string, Action> dsa4_again = new Dictionary<string, Action>() { { "one", dsa2TestOne } };        

    dsa1["one"]();
    dsa2["one"]();
    dsa3["one"]();
    dsa4["one"]();
    dsa3_again["one"]();
    dsa4_again["one"]();
}

public static Action dsa1TestOne = () => { Debug.WriteLine("TestOne"); };

public static void dsa2TestOne()
{
    Debug.WriteLine("TestOne");
}

srider1969

Here is another example of what I am asking.

        public static Dictionary<string, Action> Testing = new Dictionary<string, Action>() 
        { 
            { "one", TestOne }, 
            { "two", TestTwo }, 
        };

        static void Main(string[] args)
        {
            Testing["one"]();
        }

        public static Action TestOne = () => { Debug.WriteLine("TestOne"); };
        public static Action TestTwo = () => { Debug.WriteLine("TestTwo"); };

srider1969

Thanks for your reply.

Since the program isn't returning anything, I am unsure how I would use Func. Could you elaborate?

srider1969

How can I change the signature of my Action delegates to NOT use void methods in my Dictionary<bool, Action<UrlParts, List>>?

public static Func<UrlParts, List<UrlParts>, bool> LacksDomainPage = (up, lup) => !lup.Contains(up);

public static Action<UrlParts, List<UrlParts>> LacksUrl = (up, lup) => dicAddDomainPage[LacksDomainPage(up, lup)](up, lup);

public static Dictionary<bool, Action<UrlParts, List<UrlParts>>> dicAddDomainPage
                = new Dictionary<bool, Action<UrlParts, List<UrlParts>>>() { { true, AddDomainPage }, { false, AddNothing }, };

using

public static Action<UrlParts, List<UrlParts>> AddDomainPage = (up, ldp) => ldp.Add(up);
public static Action<UrlParts, List<UrlParts>> AddNothing = (up, ldp) => { };

instead of

public static void AddDomainPage(UrlParts up, List<UrlParts> ldp)
{
    ldp.Add(up);
}

public static void AddNothing(UrlParts up, List<UrlParts> ldp) { }

srider1969

The problem ended up being a combination of the query and data format.

srider1969

Thank you in advance. I believe the items below should give a whole view.

.Net 4.5.1 / x86

When using a SqlAdapter with new SqlParameter() { SqlDbType = SqlDbType.DateTime, ParameterName = "@FromDate", Value = "09/01/2008" },
I get the error "Conversion failed when converting date and/or time from character string" at the SqlAdapter.Fill method.

After trying every date format I could find, specifying the CommandType and DataType, I still get the above error.

If I replace the ParameterName with that date in the CommandText and add no SqlParameters, the SqlAdapter returns the expected records.

What am I missing?

public SqlConnection Connection { get; set; }

public CSqlServerDL(string Key, string Database)
{
    this.Connection = new SqlConnection(string.Format(CSqlServerDLHelper.GetConnString(Key), Database));
}

public void Execute(DataSet ds, List<CSqlServerDLTransactionObj> lis_sto)
{
    if (Connection.Equals(null) || string.IsNullOrEmpty(Connection.ConnectionString))
    {
        return;
    }

    try
    {
        using (Connection)
        {
            Connection.Open();

            foreach (CSqlServerDLTransactionObj sto in lis_sto)
            {
                if (!string.IsNullOrEmpty(sto.TableName))
                {
                    FillDataSet(sto, ds, DebugExecute);
                    continue;
                }
            }
        }
    }
    catch (Exception exc)
    {
        Debug.WriteLine(exc.Message);
    }
    finally
    {
        Connection.Close();
    }
}

private void FillDataSet(CSqlServerDLTransactionObj sto, DataSet ds)
{
    SqlDataAdapter sa = new SqlDataAdapter(sto.Command.CommandText, Connection);
    sa.SelectCommand.CommandType = CommandType.Text;

    if (sto.Parameters.Count.Equals(0))
    {
        int intRecords = sa.Fill(ds, sto.TableName);
        return;
    }

    try
    {
        sto.Parameters.ForEach(lis_sp =>
        {
            lis_sp.ForEach(sp => sa.SelectCommand.Parameters.AddWithValue(sp.ParameterName, sp.Value));

            sa.Fill(ds, sto.TableName);

            sa.SelectCommand.Parameters.Clear();
        });
    }
    catch (SqlException se)
    {
        Debug.WriteLine(se.Message);
    }
    catch (Exception e)
    {
        Debug.WriteLine(e.Message);
    }
}